Welcome to the VanDyke Software Forums

Join the discussion today!


Go Back   VanDyke Software Forums > Scripting

Reply
 
Thread Tools Rate Thread Display Modes
  #1  
Old 05-29-2019, 03:11 AM
Bruno74 Bruno74 is offline
Registered User
 
Join Date: May 2019
Posts: 4
Retrieve logs from routers and save in an excel file

Hello to all.

Sorry my English, i´m for Portugal

I´m very very new to this.... but i would like to do the following if possible:
Using Secure CRT 8.0.1

I would like to click on a VBS script and that would automatically connect to 10 different routers and retrieve yesterday Log from them (command=show log). Only yesterday log, IF exists. If NOT, ignore and go to next.

The Output should be in a XLS file that should open automatic with 11 different tabs (First tab is for a resume). One for each Log of the individual router. If the yesterday log exits

On the first tab (Sheet1), i would like a list of all 10 routers in column A and on column B a "Yes, there is an yesterday log" or "No, there is no yesterday Log"

Tks a LOT in advance
Reply With Quote
  #2  
Old 05-29-2019, 09:53 AM
jpellegrini jpellegrini is offline
Registered User
 
Join Date: Mar 2019
Posts: 20
Hi Bruno74,

Quote:
Sorry my English, i´m for Portugal
Your English is great. No worries at all.

If I understand correctly, you want to have a script that will connect to 10 routers, download the "Yesterday" log files from them (if they exist) and then create an Excel spreadsheet with a different page for each log file that was found. The first page of this Excel document should be a summary of the logs that were found and not found. Is this correct?

Writing custom scripts such as this is beyond the scope of support we generally offer; however, I can point you to some resources that will help you write the script:

1. Open multiple sessions:
https://forums.vandyke.com/showpost....94&postcount=1

You'll specifically need the pieces pertaining to opening the "Hosts" file and connecting to those hosts.

2. Download a file if it is present:
https://forums.vandyke.com/showpost....90&postcount=1

This uses an SFTP to retrieve the desired file.

3. Writing data to an Excel spreadsheet:
https://forums.vandyke.com/showpost....06&postcount=1


With these resources, you should be able to get something working that will get you close to what you are aiming for.

If you have any specific questions, please let us know.

Thanks!
__________________
Thanks,
--Jon

VanDyke Software
Technical Support
support@vandyke.com
(505) 332-5730
Reply With Quote
  #3  
Old 05-31-2019, 02:16 AM
Bruno74 Bruno74 is offline
Registered User
 
Join Date: May 2019
Posts: 4
Hi, jpellegrini.

I´m sorry for the late response and yes, you are correct.
As progresses i managed to connect to one router, retrieve yesterday log and export to excel.

The problem now is with the logs that are not found, no "yesterday log".

In this case, i would like it to be in the summary sheet, next to the router name a warning, like "No log".

Is there a way to put an "IF there´s nothing to copy THEN write "No log" in excel"....?
There is no output from the router.

Thank you!
Reply With Quote
  #4  
Old 05-31-2019, 11:55 AM
jpellegrini jpellegrini is offline
Registered User
 
Join Date: Mar 2019
Posts: 20
Quote:
Is there a way to put an "IF there´s nothing to copy THEN write "No log" in excel"....?
This is doable. If you look at the script called "SFTPTabAutomation" at the following link, you will see how to determine if the file was there (and if it transferred).

https://forums.vandyke.com/showpost....90&postcount=1

The block of code you will need is:

Code:
  If Instr(strResults, "100%") > 0 Then
        ' Put the information we received from the screen into an array
        ' where each line of the output gathered is in a unique element
        ' of the array
        vDataLines = Split(strResults, vbcrlf)
        ' Display success along with the 2nd-to-last line of the information;
        ' that's the line that contains stats about the successful transfer.
        crt.Dialog.MessageBox _
            "File transfer successful: " & vbcrlf & vbcrlf & _
            vDataLines(UBound(vDataLines) - 1)
    Else
        crt.Dialog.MessageBox _
            "Failed to get file!" & vbcrlf & vbcrlf & strResults
    End If
With this, you'll need to replace the "Failure" message box with updating your xml spreadsheet. The code to accomplish this can be found in the other link I provided you (https://forums.vandyke.com/showpost....06&postcount=1) under the heading "Excel Spreadsheets - Reading and Writing".

Using these pieces, are you able to get your script working as desired?
__________________
Thanks,
--Jon

VanDyke Software
Technical Support
support@vandyke.com
(505) 332-5730
Reply With Quote
  #5  
Old 05-31-2019, 07:16 PM
Bruno74 Bruno74 is offline
Registered User
 
Join Date: May 2019
Posts: 4
Tks Jon for your eplay

Having trouble returning the “No log” values to excel when there is no yesterday log..
The Log is not a file that exist or not, I have no way to check it.
It doesn´t produce any error, just goes to prompt “#”
The only valid info to work Is an empy paste… can excel recognize an empty paste and turn it to a string saying “no log”?
Or any other suggestions...

Here is my code. It copies to XLS the "yestarday log" if exists. If doesnt exist, it copies blank...

Here is my code so far:
# $language = "VBScript"

# $interface = "1.0"


Sub main
crt.screen.synchronous = true

' Create an Excel workbook/worksheet
Dim app, wb, ws
Set app = CreateObject("Excel.Application")
Dim row, screenrow, readline, items, n_cols
row = 1
n_cols = crt.screen.columns
Dim fso, filespec
filespec = "C:\temp\test.xls"

Set fso = CreateObject("Scripting.FileSystemObject")

If (fso.FileExists(filespec)) Then
' Excel file exists, open it using Workbooks.Open
Set wb = app.Workbooks.Open(filespec)
Set ws = wb.Worksheets(1)
row = ws.UsedRange.Rows.Count

Else

' Excel file doesn't exist, use Workbooks.Add
Set wb = app.Workbooks.Add
Set ws = wb.Worksheets(1)

End If

Set ws = wb.Worksheets(1)
' Send the initial command to run and wait for the first linefeed


crt.Screen.Send(" sh log | inc May 28" & Chr(10) )

crt.Screen.WaitForString Chr(10)

' Create an array of strings to wait for.

Dim waitStrs
waitStrs = Array( Chr(10), "#" )

Do
While True
result = crt.Screen.WaitForStrings( waitStrs )
If result = 2 Then Exit Do
screenrow = crt.screen.CurrentRow -1
readline = crt.Screen.Get(screenrow, 1, screenrow, n_cols )

items = Split( readline, vbCr, -1 )
ws.Cells(row, 1).Value = items(0)
row = row + 1
Wend
Loop


wb.SaveAs("C:\temp\test.xls")
wb.Close
app.Quit
Set ws = nothing
Set wb = nothing
Set app = nothing

crt.screen.synchronous = false
crt.Session.Log False
crt.Session.Disconnect

End Sub
Reply With Quote
  #6  
Old 06-03-2019, 11:34 AM
jpellegrini jpellegrini is offline
Registered User
 
Join Date: Mar 2019
Posts: 20
If I am understanding you correctly, the log isn't a file, but is instead just output to the screen, correct?

In this case, I would recommend checking to see if you were able to actually get anything from the screen. I see you are using WaitForString(), so before processing it, I would recommend seeing if your array is empty, and it is, don't add it to the worksheet.

Custom script support is beyond the scope of the support we offer, so I can't help too much beyond this, but you should be able to check if your array is empty or not.
__________________
Thanks,
--Jon

VanDyke Software
Technical Support
support@vandyke.com
(505) 332-5730
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -6. The time now is 11:16 PM.