Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Automated tasks using SSH to a Cisco switch

Status
Not open for further replies.

kmomberg

MIS
Jul 19, 2002
18
0
0
US
I would like to automate common tasks to a Cisco switch for documentation purposes and routine administrivia using SSH. The tasks should be stored as macros so I can run and reuse them as needed. Authentication to the switches would need to be automated as well since we have ~20 separate switches to manage. I had a VB program which would monitor the TCP ports over a telnet connection but since we went to SSH, this program is useless. Are there any free utilities or VB code snipets to accomplish this? I already looked at Putty but did not get the authentication to work since I was bouncing from one section of the documentation to another.
 
I use Tera Term Pro (yes it's free!!). YOu can download it from the following link


It can do virtually anything you want using macros. I always use ssh to connect with it and have, in the past, used it to do interesting stuff like connect to 50 routers and issue the same commands (e.g. show run and show ver) or even make config changes (such as updating a VTY ACL etc).

It's a great free product imho.

HTH
 
I heard of this product before but discounted it because all everyone everyone was talking about was Putty.

I downloaded and installed v3.1.3. I used the TT interface to initially communicate with a test switch. No problem. I then found the command line options and gave them a try. I specified something like "ttermpro <host>:22". All I see on the screen is a line "SSH-1.99-Cisco-1.25". When I hit a key, the session closes. The DOC is minimal. Do you have any samples of logging on to one of your switches or routers using SSH and executing a sample macro from the command line? Do you need to specify the SSH login ID and password or is that stored in a database when you log on manually?
 
Below is a macro I developed for Tera Term. Basically it scans a seperate text file (called IPaddresses.txt - you'll need to create this text and simply put the IP addresses of the devices you want to connect to). It will also scan an encrypted password file called password.dat (don't create this file manually - when you run the macro the 1st time it will ask you for the passwords once and automatically create this file thus you won't be asked again for the device passwords unless you remove this file). It will then ssh to each IP address it has found and will issue 3 commands: terminal length 0, show run and logout and save the output to a text file called yyyymmdd-ios-configs.txt where yyyymmdd is the date you ran the macro.

name = 'name'
address = 'address'
pwd1 = 'null1'
pwd2 = 'null2'
pwd3 = 'null3'
username = 'null4'


ioslogin = 'Password:'
iosenable = 'Password:'
badpasswords = '% Bad passwords'
badsecrets = '% Bad secrets'
iosenaprompt = '#'
iosprompt = '>'
suffix = '-ios-configs.txt'

timeout = 10
delimiter = '*'

:START

getdate yyyymmdd
strconcat yyyymmdd suffix
logopen yyyymmdd 0 0
logpause
getpassword 'password.dat' 'ios-base' pwd1
getpassword 'password.dat' 'ios-enable' pwd2


:OPENFILE
fileopen fhandle 'IPaddresses.txt' 0


:LOOPSTART

:GETNAME
filereadln fhandle name
if result = 1 goto NOMOREHOSTS
strcompare name delimiter
if result = -1 goto GETNAME
send 'ssh '
sendln name

:LOGIN
wait ioslogin
if result = 0 goto HOSTTIMEOUT
if result = 1 goto ENTERPWD

:ENTERPWD
sendln pwd1
wait iosprompt ioslogin badpasswords
if result = 0 goto DIALOGUEERROR
if result = 1 goto ENABLEMODE
if result = 2 goto ENTERPWD
if result = 3 goto BADPASSWORD

:ENABLEMODE
sendln 'enable'
wait iosenable iosenaprompt
if result = 0 goto DIALOGUEERROR
if result = 1 goto ENTERSECRET
if result = 2 goto SECRETNOTSET

:ENTERSECRET
sendln pwd2
wait iosenaprompt iosenable badsecrets
if result = 0 goto DIALOGUEERROR
if result = 1 goto BEGINCOMMAND
if result = 2 goto ENTERSECRET
if result = 3 goto BADSECRET

:BEGINCOMMAND
logstart
sendln 'terminal length 0'
wait iosenaprompt
if result = 0 goto DIALOGUEERROR
sendln
wait iosenaprompt
if result = 0 goto DIALOGUEERROR
sendln 'show run'
wait iosenaprompt
if result = 0 goto DIALOGUEERROR
logpause


:ENDCOMMAND

:LOGOUT
sendln 'logout'
wait unixprompt

:ANYMORE
goto LOOPSTART

:NOMOREHOSTS
 
I was stepping through your example to get a feel for how TeraTerm could be used to get the switch details. I found the SSH piece of particular interest since TT does not have a command line version of SSH available yet. Next week I will make any appropriate changes to your macro and run it in our environment. The first snag I see is we have a mix of CatOS and IOS switches. The versions of CatOS we are running does not support the ssh command. I tried to connect to one of them, am prompted for the password, but am ultimately informed the connection was aborted. We have only about 5 CatOS switches so until another solution comes along, I will be doing them manually. Thanks for pointing me in the right direction.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top