#1
|
|||
|
|||
![]()
Any help guys?
My script actually is not mine. It does simply telnet multiple devices then issue commands. I tried to modify it that if telnet fails it should try to use ssh instead by if else and waitforstring However from our Jumpserver, when the telnet fails like this below (simulate): 10.10.10.10 only allows ssh, it should try to waitforstring and then if the condition is true(login prompt) use ssh instead if > = false means it was able to go to the router privilege mode Trying 10.10.10.10... telnet: connect to address 10.10.10.10: Connection refused telnet: Unable to connect to remote host: Connection refused JUMPSERVER# All the syntax below are not being evaluated after the failed telnet I tried to verify and just send a string after the failed connection and it doesn't work. So there must be some additional lines to add to the telnet connection if it fails. Am i missing something here? I need to make the If then statement work if the telnet fails to use ssh instead. Attaching the script: Code:
#$language = "VBScript" #$interface = "1.0" crt.Screen.Synchronous = True sub Main Const DEVICE_FILE_PATH = "C:\XXXX\devices.txt" Const COMMANDS_FILE_PATH = "C:\XXXX\commands.txt" dim fso set fso = CreateObject("Scripting.FileSystemObject") dim fil set fil = fso.OpenTextFile(DEVICE_FILE_PATH) const username = "XXXX" ' Username for login const password = "XXXX" ' Password for login const enable = "XXXX" ' Enable for login 'turn on synchronous mode so we don't miss any data crt.Screen.Synchronous = True 'ENABLING LOGGING '----------------------------------------------------------------- If crt.Session.Logging Then crt.Session.Log False End If crt.Session.LogFileName = "C:\XXXX.txt" If crt.Session.Logging <> True Then crt.Session.Log True End If '----------------------------------------------------------------- 'END OF ENABLING LOGGING While Not fil.AtEndOfStream ip = fil.ReadLine crt.Screen.Send "telnet " & ip & vbcr crt.Screen.WaitForString "Username: " crt.Screen.Send username & vbcr crt.Screen.WaitForString "Password:" crt.Screen.Send password & vbcr dim result result = crt.Screen.WaitForStrings("JUMPSERVER#", ">", 10) If result = 1 Then crt.Screen.WaitForString "JUMPSERVER#" crt.Screen.Send "ssh -l XXXX " & ip & vbcr crt.Screen.WaitForString "Password: " crt.Screen.Send password & vbcr End If If result = 2 Then crt.Screen.WaitForString ">" crt.Screen.Send "en" & vbcr crt.Screen.Send enable & vbcr crt.Screen.WaitForString "#" End If dim com set com = fso.OpenTextFile(COMMANDS_FILE_PATH) While Not com.AtEndOfStream ioscommand = com.ReadLine crt.Screen.Send ioscommand & vbcr wend com.Close crt.Screen.Send "exit" & vbcr crt.Screen.WaitForString "JUMPSERVER#" wend fil.Close 'turn off synchronous mode to restore normal input processing crt.Screen.Synchronous = False end Sub |
Tags |
failedremote , ssh , telnet , waitforstring |
Thread Tools | |
Display Modes | Rate This Thread |
|
|