cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
4448
Views
0
Helpful
9
Replies

Run commands through Telnet?

dkinghorn
Level 1
Level 1

Hi,

I would like to be able to setup a script file that would remote into 20 or so switches, and make a few configuration changes. Does anyone know if I can create a batch/script file that would telnet to the switch and run a command on the switch, say the clear counters command, and then telnet to another switch?

thanks for any ideas,

Dave

9 Replies 9

rmushtaq
Level 8
Level 8

You can write your own perl/expect scripts for this purpose.

You could also use RME's Netconfig application, if you have CiscoWorks2000. It lets you make same config changes on a number of devices.

-Ganesh.

jmoore
Level 1
Level 1

Dave,

I have been using a free package called Expect running on Redhat Linux. This package performs the functions of an interactive telnet session giving responses based on if / then types of interactions.

Joseph

b.obrien
Level 1
Level 1

Dave,

I found the netconfig under RME/configuration managment is the best way to change router or switch configs.

But if you just what to see certain show commands, for instance frame PVC's active on a router. This is the script I have been using just a simple shell script. Run this script via ./do-telnet | telnet > output.file

#!/bin/ksh

# As of 4/5/02 08:40am

# This script is test a telnet and produce a file on the output.

host=router.your.domain.com

port=23

login=tacacs

passwd=tacacs

cmd1="term length 0"

cmd2="sh frame pvc"

echo open ${host} ${port}

sleep 1

echo ${login}

sleep 1

echo ${passwd}

sleep 1

echo ${cmd1}

sleep 1

echo ${cmd2}

sleep 1

echo exit

Bill

jgercken
Level 1
Level 1

If you want quick and dirty try CatTools by Kiwi software (shareware)

http://www.kiwisyslog.com/

-Jeff

russ.laplante
Level 1
Level 1

I like Expect for tasks like these. I am not a programmer, I am not very good at scripting, and I have managed to script some tasks that we usually use interactive CLIs for.

It runs on UNIX or Window. I prefer to run it from a Solaris box.

Here is a little snippet of Perl to try (it works for me):

use Net::Telnet ();

$switch_ip = "ip address of switch";

$password1 = "your line password";

$password2 = "your enable password";

$t = Net::Telnet->new( Timeout => 10);

$t->open($switch_ip);

$t->waitfor('/:/');

$t->print($password1);

$t->waitfor('/>/');

$t->print("enable\n");

$t->waitfor('/:/');

$t->print($password2);

$t->waitfor('/#/');

$t->print("term length 0\n");

$t->waitfor('/#/');

...continue using waitfor() function to interact with telnet host...

I hope it helps.

I too wrote something using Perl's Net::Telnet module, but rather than writing a new script each time I designed a very simplistic "language" that's interpreted by the script. For example, you can turn debugging on and off, and output on and off (sometimes you only want to capture the output from one of a series of IOS command). So, all you need to do is write a bunch of command scripts rather than a new Perl program each time.

Drop me a line if you'd like a copy. I'm happy to share it.

rvandell
Level 1
Level 1

Hi,

You might check out the jakarta.org website about ANT

which can be used from both PC's and linux/Unix.

http://jakarta.apache.org/ant

I had this bet with a person that a 1 year development

project written in C++ to address things like global

commuunity string re-setting, (their _older_ nodes only have telnet, no SNMP), and SNMP-less status polling

could easily be completed in three or four months...

Ok, I admit it, I_WAS_WRONG....

Using ANT try 3 WEEKS!

While network management may not look like config mgmt, you'll be hard pressed to point out the differences

between a multi-OS software release and multi-vendor

topolology (re)configuration.

The real bang is that you can extend ANT using java

and (whatever they don't already have, you add on

yourself). See Taskdef.

I can envision ANT calling JMX (Sun tm.) to do the

SNMP things, and calling telnet to do the others..

(or JMX calling an SMNP trap to an ANT Task MLET)

SweeeeeeeeeeeeeeeT! (I'm working on it).

Goto the ANT Documentation page,

http://jakarta.apache.org/ant/manual

then look at Builtin Tasks and Optional tasks.

Then being an engineer... download it and enjoy

over the weekend... You'll be happy happy joy joy....

Sincerely,

RobV.

AdsAlive Inc.

Review Cisco Networking for a $25 gift card