Welcome to the VanDyke Software Forums

Join the discussion today!


Go Back   VanDyke Software Forums > Scripting

Notices

Reply
 
Thread Tools Rate Thread Display Modes
  #1  
Old 02-21-2012, 08:19 AM
stuartX stuartX is offline
Registered User
 
Join Date: Feb 2012
Posts: 33
Log into Cisco router, perform cmds and log to a file

I'm having difficulty in creating a script to log into a cisco router, prompted with username and password, perform commands and log to a file.
I saw an example. I'm able to log into the router with username and password.
Is there an example I can use to refer to?
Thanks for help (in advance)
Reply With Quote
  #2  
Old 02-21-2012, 08:31 AM
rtb rtb is offline
VanDyke Technical Support
 
Join Date: Aug 2008
Posts: 4,305
Hi stuartX,

Thanks for the question. We have examples as well as information explaining how the examples work in the scripting manual that we published to www.vandyke.com. You can find the downloadable PDF file at the following location:
http://www.vandyke.com/support/tips/...ing/index.html
Chapter 3 discusses connecting to remote machines, chapters 4 and 5 discuss interacting with the remote machine (performing commands) and chapter 7 discusses logging data to files.

Does this information help as you write your script?

Did you have any specific questions about the example you found?

If so, would you post them along with the example you are referencing?
__________________
--Todd

VanDyke Software
Technical Support
support@vandyke.com
505-332-5730
Reply With Quote
  #3  
Old 02-21-2012, 08:40 AM
stuartX stuartX is offline
Registered User
 
Join Date: Feb 2012
Posts: 33
Yes, I have questions. I searched and found an example from this link:
http://forums.vandyke.com/showthread.php?p=14178

I copied the example and changed the path for the Devices.txt file and of course modified the text file contents (x.x.x.x;Telnet).
When I run the script, I get pass username and password. But it stops and nothing else happens.
Reply With Quote
  #4  
Old 02-21-2012, 08:54 AM
rtb rtb is offline
VanDyke Technical Support
 
Join Date: Aug 2008
Posts: 4,305
Hi stuartX,

Thanks for the update. Would you post the script you are using in your tests in a code block?

Would you also cancel the script (Script / Cancel) when it is doing nothing, and tell me on what line the script is stopped?
__________________
--Todd

VanDyke Software
Technical Support
support@vandyke.com
505-332-5730
Reply With Quote
  #5  
Old 02-21-2012, 09:02 AM
stuartX stuartX is offline
Registered User
 
Join Date: Feb 2012
Posts: 33
How do I create a code block on this forum?
Is the beginning
Code:
 and after
?
Reply With Quote
  #6  
Old 02-21-2012, 09:16 AM
stuartX stuartX is offline
Registered User
 
Join Date: Feb 2012
Posts: 33
How do I create the code block? or should I just copy/paste?
Reply With Quote
  #7  
Old 02-21-2012, 09:21 AM
stuartX stuartX is offline
Registered User
 
Join Date: Feb 2012
Posts: 33
Here is the code from the link modified

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

Sub Main
	
	Dim fso
	Dim fil
	Dim Connected
	Dim UID
	Dim DeviceType
	Dim Password
	Dim Router
	Dim protocol
	Dim LogFileLocation
 
'******************************
'******************************
'   LOCATION OF LOG FILE
 
 LogFileLocation = "S:\Riggs\"
 
'******************************
'******************************
 
	Const DEVICE_FILE_PATH = "S:\Riggs\Devices.txt"
	Set fso = CreateObject("Scripting.FileSystemObject")
	Set fil = fso.OpenTextFile(DEVICE_FILE_PATH)
	UID = GetUID()
 	crt.Session.Disconnect
 
	While Not fil.AtEndOfStream
		line = fil.ReadLine
		
		Router = Split(line, ";")(0)
		protocol = Split(line, ";")(1)
		Password = GetPassword()
		
		Select Case protocol
			Case "Telnet"
				cnxnString = "/TELNET " & Router & " 23"
			Case "SSH2"
				cnxnString = "/SSH2 /L " & UID & " /PASSWORD " & password & " /C 3DES /M MD5 " & Router
			Case "SSH1"
				cnxnString = "/SSH1 /L " & UID & " /PASSWORD " & password & " /C 3DES /M MD5 " & Router
		End Select	
		
		crt.Session.Connect cnxnString
		crt.Screen.Synchronous = True
		If protocol = "Telnet" then
			crt.Screen.WaitForString "Username:"
			crt.Screen.Send UID & chr(13)
			crt.Screen.WaitForString "Password:"
			crt.Screen.Send Password & chr(13)
		End If
		crt.Screen.WaitForStrings Router + "#",  Router + "> (enable)"
		crt.Screen.Send "sh ver " + chr(124) + " i IOS" + chr(124) + "Sw" + chr(13)
		crt.Screen.WaitForStrings Router + "#",  Router + "> (enable)"
		screenrow = crt.screen.CurrentRow
		screenrow = screenrow - 1
		tempDevice = crt.Screen.Get(screenrow, 1, screenrow, 80 )
 
		DeviceType = "CatOS"
 
 		If instr(tempDevice,"IOS") > 0 then
			DeviceType = "IOS"
		End If
			
		Dim logfile
		logfile = (LogFileLocation + Router + "-confg.txt")
		crt.Session.LogFileName = logfile
		crt.Session.Log True
			
			If DeviceType = "IOS" then
				crt.Screen.Send "term len 0" & chr(13)
				crt.Screen.WaitForStrings Router + "#",  Router + "> (enable)"
				crt.Screen.Send "sh run" & chr(13)
				crt.Screen.WaitForStrings Router + "#",  Router + "> (enable)"
			End If
			If DeviceType = "CatOS" then
				crt.Screen.Send "set length 0" & chr(13)
				crt.Screen.WaitForStrings Router + "#",  Router + "> (enable)"
				crt.Screen.Send "sh conf" & chr(13)
				crt.Screen.WaitForStrings Router + "#",  Router + "> (enable)"
			End If
 
			crt.Session.Log False
			crt.Session.Disconnect
	
	Wend
			fil.Close 
End Sub
 
'**************************************************************************************
Function GetPassword()
 Dim TempPassword
 Do
  TempPassword = crt.Dialog.Prompt("Enter Password:","Password","",True)
  If TempPassword = "" Then 
   result = crt.Dialog.MessageBox("Password cannot be blank. Retry?","No Password",4)
    If result = 7 then
     crt.quit
    End If
  End If
 Loop Until TempPassword<>""
 GetPassword=TempPassword
 Exit Function
End Function 
 
'**************************************************************************************
Function GetUID()
  dim TempUID
  Do
   TempUID = crt.Dialog.Prompt("Enter UserID:","UserID","",False)
   If TempUID = "" Then 
    result = crt.Dialog.MessageBox("UserID cannot be blank. Retry?","No Userid",4)
    If result = 7 then
     crt.quit
    End If
   End If
  Loop Until TempUID<>""
  GetUID=TempUID
  Exit Function
End Function
I really don't care about "IOS" or "CATOS".
It stops at line #56.
Reply With Quote
  #8  
Old 02-21-2012, 09:26 AM
rtb rtb is offline
VanDyke Technical Support
 
Join Date: Aug 2008
Posts: 4,305
Hi stuartX,

Thanks for posting the code in a code block.

Here is line 56:
Code:
		crt.Screen.Send "sh ver " + chr(124) + " i IOS" + chr(124) + "Sw" + chr(13)
Are you saying that you never see "sh ver...", or you see that, but nothing happens after you see that sent to the remote device?

Is line 56 in your script editor the same as the line I pasted above?

I think that you may have better luck using the examples in the scripting manual that I referenced rather than trying to repurpose this example to your needs.
__________________
--Todd

VanDyke Software
Technical Support
support@vandyke.com
505-332-5730
Reply With Quote
Reply

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 10:56 AM.