View Single Post
Old 01-21-2007, 04:53 AM
wirelessmonk01 wirelessmonk01 is offline
Registered User
Join Date: Nov 2006
Posts: 16
OK, as I am prone to do, I am doing all my own thread answering. I'm not completely out of the woods yet, but I'm getting closer. I can now start a script which loads a session, telnets into the first router on the list, and enters the username and password. At this point in my script I have it waiting for the ">" that indicates global config mode. From there it takes the steps to enter enable mode. The problem is: some of the routers are in enable mode by default. So instead of a ">" when I log in, there is a "#" waiting for me. This is only some of the routers so I definitely need to keep the crt.Screen.WaitForString ">" in there, but how do I tell it to skip ahead if it doesn't find it in say...15 seconds??

I fully expect I'll find the answer somewhere and post my own reply (nobody else seems to be up at this time of...morning, and I don't blame you!)

Here's the script so far...feel free to constructively criticize.

#$language = "VBScript"
#$interface = "1.0"

Sub Main
	Const username = "xxxxxx" ' Username to use for login
	Const password = "xxxxxxx" ' Password for corresponding user
	Const loginPass = "xxxxxxxx" ' Password to use for password only login (aka no aaa new-model)
	Const DEVICE_FILE_PATH = "C:\Documents and Settings\xxxxxx\Desktop\devicestest.txt"
	Dim fso
	Set fso = CreateObject("Scripting.FileSystemObject")
	Dim fil
	Set fil = fso.OpenTextFile(DEVICE_FILE_PATH)

	crt.session.Connect("/s xxxxxxxxxxxx")
	Dim ip
	Dim name
	Dim line
	While Not fil.AtEndOfStream
		line = fil.ReadLine
		name = Split(line, ",")(0)
		ip = Split(line, ",")(1)
		crt.session.Log True
		crt.session.Logfilename = "C:\Documents and Settings\xxxxxx\Desktop\backup_configs\"&name&".log"
		' Connect 
		crt.Screen.Synchronous = True		
		crt.Screen.Send "telnet " & ip &  vbCr
		' Enable
		crt.Screen.WaitForString "sername:"
		crt.Screen.Send username & vbCr
		crt.Screen.WaitForString "assword"
		crt.Screen.Send password & vbCr
		crt.Screen.WaitForString ">"
		crt.Screen.Send "en" & vbCr
		crt.Screen.WaitForString "assword"
		crt.Screen.Send loginPass
		crt.Screen.WaitForString "#"
		crt.Screen.Send "sh run"
		crt.Screen.Send " "
		crt.Screen.Send " "
		crt.Screen.Send " "
		crt.Screen.Send " "
		crt.Screen.Send " "
		crt.Screen.Send " "
		crt.Screen.Send " "
		crt.Session.Log False

End Sub
Reply With Quote