#31
|
|||
|
|||
Hi stuartX,
Thanks for the screenshots. The connection string is empty. This is why there is no connection and the script is failing on line 48. Can you confirm that the path to the list of devices is valid? Would you post or send the script you are using when you see this issue? |
#32
|
|||
|
|||
Yes, the file path is there (attached screenshot). And the router device is up on the network and is accessible via telnet.
Below is the code: Code:
# $language = "VBScript" # $interface = "1.0" Sub Main strUsername = "user" strPassword = "password" strPrompt = "#" Set fso = CreateObject("Scripting.FileSystemObject") strDeviceList = "s:\riggs\Test-router-1.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) strProtocol = vLine(2) ' Generate a connection string Select Case strProtocol Case "Telnet" cnxnString = "/TELNET " & strIP & " 23" ' Don't wait for connection to complete before moving on because ' we are going to handle authentication after connecting. bWait = False Case "SSH2" cnxnString = "/SSH2 /L " & strUsername & " /PASSWORD " & strPassword & " " & strIP ' Wait for connection to complete before moving on. bWait = True Case "SSH1" cnxnString = "/SSH1 /L " & strUsername & " /PASSWORD " & strPassword & " " & strIP ' Wait for connection to complete before moving on. bWait = True End Select 'Handle possible errors when connecting crt.Dialog.MessageBox "Connect string:" & vbcrlf & vbtab & cnxcString &_ vbcrlf & "Should I wait:" & vbcrlf & vbtab & bWait On Error Resume Next crt.Session.Connect cnxnString, bWait strErr = Err.Description nError = Err.Number On Error Goto 0 ' Enable Synchronous which is necessary for not missing data from remote crt.Screen.Synchronous = True ' Handle Telnet authentication If strProtocol = "Telnet" Then crt.Screen.Send vbcr nIndex = crt.Screen.WaitForStrings("login:", "Password:") ' Handle authentication starting at username If nIndex = 1 Then crt.Screen.Send strUsername & vbcr crt.Screen.WaitForString "Password:" crt.Screen.Send strPassword & vbcr ' Handle authentication starting at password Else crt.Screen.Send strPassword & vbcr End If End If ' Confirm that remote is ready crt.Screen.WaitForString strPrompt ' Start logging to new file strLogFile = "C:\Switches\" & strHostname & "-%Y-%M-%D--%h-%m-%s.%t.txt" crt.Session.LogFileName = strLogFile crt.Session.Log True ' Turn off paging crt.Screen.Send "term length 0" & vbcr crt.Screen.WaitForString strPrompt ' Send commands crt.Screen.Send "show proc cpu | inc CPU" & vbcr crt.Screen.WaitForString strPrompt crt.Screen.Send "show version" & vbcr crt.Screen.WaitForString strPrompt ' Stop logging crt.Session.Log False ' Disconnect from device If crt.Session.Connected Then crt.Session.Disconnect End If Wend ' Close device file fil.Close End Sub |
#33
|
|||
|
|||
I forgot the attached.
|
#34
|
|||
|
|||
Hi stuartX,
Thanks for the screenshots and code. I have an idea to try and ferret out the cause of the issue. Please add an Else case to the Select Case statement (I included a few lines above and below where it needs to be placed): Code:
. . . Case "SSH1" cnxnString = "/SSH1 /L " & strUsername & " /PASSWORD " & strPassword & " " & strIP ' Wait for connection to complete before moving on. bWait = True Case Else ' We should never get here, but if we do, we need to know. crt.Dialog.MessageBox _ "strProtocol contains no recognized protocol:" & vbcrlf &_ vbtab & strProtocol End Select . . . Does the protocol exactly match one of the valid cases in the Select Case statement? |
#35
|
|||
|
|||
I inserted the additional script. I've attached the two popups (attached; popup-1.jpg and popup-2.jpg) that I received. the second point to line 53. My line 53 is:
nIndex = crt.Screen.WaitForStrings("login:", "Password:") |
#36
|
|||
|
|||
Hi stuartX,
I found a typo in the code I posted previously. Lines 39 and 40 should be: Code:
crt.Dialog.MessageBox "Connect string:" & vbcrlf & vbtab & cnxnString &_ vbcrlf & "Should I wait:" & vbcrlf & vbtab & bWait |
#37
|
|||
|
|||
After inserting the two lines of script. The following errors (attached telnet-1.jpg and telnet.jpg-2) involving telnet.
|
#38
|
|||
|
|||
Hi stuartX,
I have a modified example that should handle problems with connecting to remote hosts. What happens if you run the following example? Code:
# $language = "VBScript" # $interface = "1.0" Sub Main strUsername = "user" strPassword = "password" strPrompt = "#" Set fso = CreateObject("Scripting.FileSystemObject") strDeviceList = "s:\riggs\Test-router-1.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) strProtocol = vLine(2) ' Generate a connection string Select Case strProtocol Case "Telnet" cnxnString = "/TELNET " & strIP & " 23" Case "SSH2" cnxnString = "/SSH2 /L " & strUsername & " /PASSWORD " & strPassword & " " & strIP & ", True" Case "SSH1" cnxnString = "/SSH1 /L " & strUsername & " /PASSWORD " & strPassword & " " & strIP & ", True" End Select 'Handle possible errors when connecting crt.Dialog.MessageBox "Connect string:" & vbcrlf & vbtab & cnxnString 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 ' Handle Telnet authentication If strProtocol = "Telnet" Then crt.Screen.Send vbcr nIndex = crt.Screen.WaitForStrings("login:", "Password:") ' Handle authentication starting at username If nIndex = 1 Then crt.Screen.Send strUsername & vbcr crt.Screen.WaitForString "Password:" crt.Screen.Send strPassword & vbcr ' Handle authentication starting at password Else crt.Screen.Send strPassword & vbcr End If End If ' Confirm that remote is ready crt.Screen.WaitForString strPrompt ' Start logging to new file strLogFile = "C:\Switches\" & strHostname & "-%Y-%M-%D--%h-%m-%s.%t.txt" crt.Session.LogFileName = strLogFile crt.Session.Log True ' Turn off paging crt.Screen.Send "term length 0" & vbcr crt.Screen.WaitForString strPrompt ' Send commands crt.Screen.Send "show proc cpu | inc CPU" & vbcr crt.Screen.WaitForString strPrompt crt.Screen.Send "show version" & 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; 02-28-2012 at 01:13 PM. |
#39
|
|||
|
|||
I loaded the script. I've attached the screenshots (there were six, but there's a limit for five). But its a repetitive error.
|
#40
|
|||
|
|||
Hi stuartX,
I have edited the script example in post #38. Would you test this and let me know the results? |
#41
|
|||
|
|||
That's what the five screenshots were from post#38 script run.
|
#42
|
|||
|
|||
Hi stuartX,
I actually made changes to the script in post #38. There was a typo and I made some changes to the connection strings that may be affecting you, but not me in my test environment. Would you run the example again and let me know what your results are with the changes? |
#43
|
|||
|
|||
I loaded the modified script and something interesting happend. The script went through telneted to the first device (attachment line38-1.jpg shows this) and performed all three commands successfully. Then opened a session with second device (attached line38-2.jpg), got prompted with username but it seems like the script sent a carriage return then sent the username (shown in line38-3.jpg (password crossed out in red)). After that it sat there (also shown in line38-3.jpg) I then cancelled which showed stopped at line 52.
|
#44
|
|||
|
|||
Hello stuartX,
Todd is out of the office. When I test that section of the code posted in #38, it works as expected. Just to verify, the data you redacted (in line38-3.jpg) was the password, not the username? Also, have you plugged in the correct Username, Password and Prompt on lines 4-5-6 of the example script? In case anything has been changed, would you post the current rendition of script "Logging Script-Forum-4modified.vbs"? Redact sensitive data as necessary.
__________________
Thanks, --Brenda VanDyke Software Technical Support support@vandyke.com (505) 332-5730 |
#45
|
|||
|
|||
As I mentioned before, the script works on the first device (login, commands, logout), but on the second device it opens a session, but seems like it does a carriage return then sends the username.
Please keep in mind that the username password that I send in the script is not the actual username password used on the three Nexus routers. I did that so that I would not reveal my password on the forum. Also, keep in mind that all three devices have the same username and password. And, if i separately telnet into each one the credentials work. My actual username is "admin". Below is the code, I'm using: Code:
# $language = "VBScript" # $interface = "1.0" Sub Main strUsername = "user" 'not real username strPassword = "password" 'not real password strPrompt = "#" Set fso = CreateObject("Scripting.FileSystemObject") strDeviceList = "s:\riggs\Test-router-1.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) strProtocol = vLine(2) ' Generate a connection string Select Case strProtocol Case "Telnet" cnxnString = "/TELNET " & strIP & " 23" Case "SSH2" cnxnString = "/SSH2 /L " & strUsername & " /PASSWORD " & strPassword & " " & strIP & ", True" Case "SSH1" cnxnString = "/SSH1 /L " & strUsername & " /PASSWORD " & strPassword & " " & strIP & ", True" End Select 'Handle possible errors when connecting crt.Dialog.MessageBox "Connect string:" & vbcrlf & vbtab & cnxnString 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 ' Handle Telnet authentication If strProtocol = "Telnet" Then crt.Screen.Send vbcr nIndex = crt.Screen.WaitForStrings("login:", "Password:") ' Handle authentication starting at username If nIndex = 1 Then crt.Screen.Send strUsername & vbcr crt.Screen.WaitForString "Password:" crt.Screen.Send strPassword & vbcr ' Handle authentication starting at password Else crt.Screen.Send strPassword & vbcr End If End If ' Confirm that remote is ready crt.Screen.WaitForString strPrompt ' Start logging to new file strLogFile = "S:\Riggs\" & strHostname & "-%Y-%M-%D--%h-%m-%s.%t.txt" crt.Session.LogFileName = strLogFile crt.Session.Log True ' Turn off paging crt.Screen.Send "term length 0" & vbcr crt.Screen.WaitForString strPrompt ' Send commands crt.Screen.Send "show proc cpu | inc CPU" & vbcr crt.Screen.WaitForString strPrompt crt.Screen.Send "show version" & 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 |
![]() |
Thread Tools | |
Display Modes | Rate This Thread |
|
|