View Single Post
  #5  
Old 06-22-2015, 09:09 AM
mms mms is offline
Registered User
 
Join Date: Jun 2015
Posts: 4
Here it is. I did modified some of the details same as previous due to sensitive info.

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)
	crt.Dialog.MessageBox result

	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