Welcome to the VanDyke Software Forums

Join the discussion today!


Go Back   VanDyke Software Forums > Scripting

Notices

 
 
Thread Tools Rate Thread Display Modes
Prev Previous Post   Next Post Next
  #1  
Old 06-19-2015, 04:45 PM
mms mms is offline
Registered User
 
Join Date: Jun 2015
Posts: 4
Smile syntax not working after failed telnet connection

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
Reply With Quote
 

Tags
failedremote , ssh , telnet , waitforstring

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 05:24 AM.