#1
|
|||
|
|||
Logging Device from script and save to text file
I have a script with VBscript that reads the ip names/IP from a text file (IOS-Device.txt) and write to a text file in a directory (S:\Riggs\IOS Test directory).
The device text file (IOS Device.txt) contains the following: Device1;10.10.10.1;Telnet;Test1 Device2;10.10.10.2;Telnet;Test2 Device3;10.10.10.3;Telnet;Test3 This is what I want the script to do: 1. read device from file 2. log into device 3. perform commands 4. write file 5 go to next device and repeat steps. What I see is that it accesses all the devices from the file and perform the commands, I can see this on the screen scrolling through. It also saves the different file names to the proper directory. But the problem is that even though the file names are different, each file contains the commands performed on the last device in the list. For example, the saved text files 1, 2 and 3 have the same command results from Device 3. Below is my code. code: Code:
# $language = "VBScript" # $interface = "1.0" Sub Main strUsername = "admin1" 'not real username strPassword = "getin" 'not real password strPrompt = ">" Set fso = CreateObject("Scripting.FileSystemObject") strDeviceList = "s:\riggs\IOS-Device.txt" Set fil = fso.OpenTextFile(strDeviceList) ' Start loop to iterate over all devices defined in file While Not fil.AtEndOfStream ' Process a line at a time vLine = Split(fil.ReadLine, ";") strHostname = vLine(0) strIP = vLine(1) On Error Resume Next crt.Session.Connect cnxnString strErr = Err.Description nError = Err.Number On Error Goto 0 If crt.Session.Connected = False Then crt.Dialog.MessageBox "The following host cannot be reached: " &_ vbcrlf & vbtab & strHostname & vbcrlf & vbcrlf &_ "With error: " & vbcrlf & vbtab & strErr Else ' Enable Synchronous which is necessary to avoid missing data from ' remote crt.Screen.Synchronous = True crt.Screen.WaitForString "Username:" crt.Screen.Send strUsername & vbcr crt.Screen.WaitForString "Password:" crt.Screen.Send strPassword & vbcr ' Confirm that remote is ready crt.Screen.WaitForString strPrompt ' Start logging to new file strLogFile = "S:\Riggs\IOS Test\" & strHostname & "-%Y-%M-%D--%h-%m-%s.%t.txt" crt.Session.LogFileName = strLogFile crt.Session.Log True ' send deive command crt.Screen.Send "term length 0" & vbcr crt.Screen.Send "show ver" & vbcr crt.Screen.WaitForString strPrompt ' Send device commands crt.Screen.Send "show proc cpu | inc CPU" & vbcr crt.Screen.WaitForString strPrompt crt.Screen.Send "show version" & vbcr crt.Screen.WaitForString strPrompt crt.Screen.Send "show ip route summary" & vbcr crt.Screen.WaitForString strPrompt ' Stop logging crt.Session.Log False ' Disconnect from device If crt.Session.Connected Then crt.Session.Disconnect End If End If Wend ' Close device file fil.Close End Sub Last edited by rtb; 10-24-2012 at 11:32 AM. |
Tags |
log , router , textfile |
Thread Tools | |
Display Modes | Rate This Thread |
|
|