LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Networking
User Name
Password
Linux - Networking This forum is for any issue related to networks or networking.
Routing, network cards, OSI, etc. Anything is fair game.

Notices


Reply
  Search this Thread
Old 10-17-2006, 03:45 PM   #1
ping2tariq
LQ Newbie
 
Registered: Sep 2006
Posts: 17

Rep: Reputation: 0
want script to configure cisco rouers from linux


i have to fire some fix set of commands in 1000 routers.
but it's time consuming . i have to login each routers, it gives login and password prompt then have to enter some fix commands.

so dear all i want script that do this fast in linux..

Thanks in advance
 
Old 10-18-2006, 12:21 AM   #2
carl0ski
Member
 
Registered: Sep 2004
Location: Melbourne, Victoria Australia
Distribution: Support those that support you :)
Posts: 872
Blog Entries: 12

Rep: Reputation: 30
I dont remember any Cicso specific commands however this is the basic need
Code:
(sleep 3; echo username; sleep 3; echo password; sleep 5; echo ping 127.0.0.1; sleep 3; echo "exit") | telnet hostname
everything enclosed within the ( ) is executed after you telnet into the router
sleep between each command to ensure they dont overlap.
in this example after connected for 3 seconds it will
type/enter a username
Another 3 seconds will type/enter a password
another 5 seconds will run
ping 127.0.0.1

another 3 seconds will exit the telnet shell.

Last edited by carl0ski; 10-18-2006 at 12:37 AM.
 
Old 11-10-2006, 12:25 AM   #3
ping2tariq
LQ Newbie
 
Registered: Sep 2006
Posts: 17

Original Poster
Rep: Reputation: 0
thanks and want scrip to mail from command line

Dear,

First thanks for giving this logic and it helped me much to write script. but Dear i want to mail after successfully completion of script to xyz@abc.com from command line...
i wrote

[root@tariq ~]# mail -s "Reports are ---" xyz@abc.com < /root/Report

where /root/Report containing Acctual report.

but when xyz@abc.com recieve mail it display from address root@tariq.asd.com

[root@tariq ~]#hostname
tariq.asd.com

i want tariq@abc.com inplace of root@tariq.asd.com what i do?
is there any argument for from address in "mail" command?
 
Old 11-18-2006, 07:48 AM   #4
SebVT
LQ Newbie
 
Registered: Jun 2005
Location: UK
Posts: 6

Rep: Reputation: 0
It doesn't help with the mailing, but you may like to have a look at RANCID:
http://www.shrubbery.net/rancid/

It comes with a nice little expect script called clogin (i think) which handles logging into your cisco kit and issuing a few commands. You can specify username, password, and a ';' delimited list of cisco commands to run against a given router.

It can handle a lot of the awkward stuff quite nicely - i.e. routers with only telnet/enable passwords instead of those with username/password. Also it deals with both CatOS and IOS.

I then wrote a small wrapper perl script to run clogin with given cisco commands against every router listed in a text file.

Hope this helps.

Last edited by SebVT; 11-18-2006 at 07:49 AM.
 
Old 12-04-2006, 03:22 AM   #5
ping2tariq
LQ Newbie
 
Registered: Sep 2006
Posts: 17

Original Poster
Rep: Reputation: 0
don't want to exit automatic

Dear,

I am using it but i don't want to exit from telnet session automatically.
what i do?

Acctually i am creating script where i prompt for ip address and then i want to give telnet session automatically for that ip without entering login name and passwd.



Quote:
Originally Posted by carl0ski
I dont remember any Cicso specific commands however this is the basic need
Code:
(sleep 3; echo username; sleep 3; echo password; sleep 5; echo ping 127.0.0.1; sleep 3; echo "exit") | telnet hostname
everything enclosed within the ( ) is executed after you telnet into the router
sleep between each command to ensure they dont overlap.
in this example after connected for 3 seconds it will
type/enter a username
Another 3 seconds will type/enter a password
another 5 seconds will run
ping 127.0.0.1

another 3 seconds will exit the telnet shell.
 
Old 12-04-2006, 03:46 AM   #6
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,417

Rep: Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985
personally i'd strongly suggest using expect to do this. it's a great tool which can do exactly what you're after, albeit in a way that might seem confusing to start with. it's really worth pursuing though if you want to do more things such as this in the future. i use expect to automatically update configs on thousands of cisco routers automatically.
 
Old 12-04-2006, 06:34 AM   #7
ping2tariq
LQ Newbie
 
Registered: Sep 2006
Posts: 17

Original Poster
Rep: Reputation: 0
ok

ok sir , i am using expect also but i don't want telnet login prompt and password prompt. i am using this

#!/usr/bin/expect --

set timeout 180
set machine [lindex $argv 0]
set username [lindex $argv 1]
set password [lindex $argv 2]
spawn telnet $machine
send "$username\n"
send "$password\n"
interact

now what i do to achieve what i want.....



Quote:
Originally Posted by acid_kewpie
personally i'd strongly suggest using expect to do this. it's a great tool which can do exactly what you're after, albeit in a way that might seem confusing to start with. it's really worth pursuing though if you want to do more things such as this in the future. i use expect to automatically update configs on thousands of cisco routers automatically.
 
Old 12-04-2006, 06:48 AM   #8
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,417

Rep: Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985
well what's not working? all i'd suggest is actually using some expect commands, as you've none there at all, e.g.

spawn telnet $machine
expect "Username:"
send "$username\n"
Expect "Password:"
send "$password\n"
 
Old 12-05-2006, 12:27 AM   #9
ping2tariq
LQ Newbie
 
Registered: Sep 2006
Posts: 17

Original Poster
Rep: Reputation: 0
thanks to keep in touch

ok dear, but when i run this script, it prompt for username and whatever i enter "that display in terminal" so dear i want to hide username (what i enter) prompt and password prompt and direct want to enter cisco prompt acctualy i am doing telnet to cisco router.

Quote:
Originally Posted by acid_kewpie
well what's not working? all i'd suggest is actually using some expect commands, as you've none there at all, e.g.

spawn telnet $machine
expect "Username:"
send "$username\n"
Expect "Password:"
send "$password\n"
 
Old 12-05-2006, 02:48 AM   #10
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,417

Rep: Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985
dear? what's all this dear nonsense... last few weeks i've been called "dear" a dozen times by different people...

anyway, check the log_user command, which will stop things being echoed to stdout
Code:
       log_user -info|0|1
             By  default,  the send/expect dialogue is logged to stdout (and a
             logfile if open).  The logging to stdout is disabled by the  com-
             mand  "log_user 0" and reenabled by "log_user 1".  Logging to the
             logfile is unchanged.
 
Old 12-05-2006, 09:52 AM   #11
amitsharma_26
Member
 
Registered: Sep 2005
Location: New delhi
Distribution: RHEL 3.0/4.0
Posts: 777

Rep: Reputation: 31
(offtopic)

Quote:
Originally Posted by acid_kewpie
dear? what's all this dear nonsense... last few weeks i've been called "dear" a dozen times by different people...
Dear Acid,
I guess its the only "dear" thats troubling you (offlate) & probably "Dear moderator" would be ok in that case.
What you say ?

Btw google reported this for define: dear
Code:
Definitions of  dear on the Web:

    * beloved: dearly loved
    * with or in a close or intimate relationship; "a good friend"; "my sisters and brothers are near and dear"

Regards,
Amit..
 
Old 12-05-2006, 11:39 AM   #12
win32sux
LQ Guru
 
Registered: Jul 2003
Location: Los Angeles
Distribution: Ubuntu
Posts: 9,870

Rep: Reputation: 380Reputation: 380Reputation: 380Reputation: 380
Re: (offtopic)

yeah, using dear as in "dear moderator" isn't the same as using dear as in "thank you dear", "ok dear", etc... personally, i find the latter awkward for a tech support forum, but in the years i've been a member here at LQ i've seen lots of people use the awkward form of dear and i've always just assumed it's a normal way of speaking in a certain part of the world or something... =/

Last edited by win32sux; 12-05-2006 at 11:41 AM.
 
Old 12-05-2006, 10:46 PM   #13
ping2tariq
LQ Newbie
 
Registered: Sep 2006
Posts: 17

Original Poster
Rep: Reputation: 0
thanks a lot

sir, i've got what i want after using "log_user 0" in the script.
thanks a lot to be in touch for last few days.


Quote:
Originally Posted by acid_kewpie
dear? what's all this dear nonsense... last few weeks i've been called "dear" a dozen times by different people...

anyway, check the log_user command, which will stop things being echoed to stdout
Code:
       log_user -info|0|1
             By  default,  the send/expect dialogue is logged to stdout (and a
             logfile if open).  The logging to stdout is disabled by the  com-
             mand  "log_user 0" and reenabled by "log_user 1".  Logging to the
             logfile is unchanged.
 
Old 12-19-2006, 09:01 AM   #14
ping2tariq
LQ Newbie
 
Registered: Sep 2006
Posts: 17

Original Poster
Rep: Reputation: 0
expect script is not running from crond

Hi,

When i run expect script manually as root user from terminal, it's working fine but when it has been called by crond , not giving proper result. What's the problem?

[root@tariq ~]#crontab -l
5 1 * * * /usr/bin/tbackup
 
Old 12-19-2006, 09:28 AM   #15
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,417

Rep: Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985
what's a non proper result?

is the script executable?
 
  


Reply



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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
cannot configure cisco 871 series router to get online anubis65656 Linux - Networking 7 02-23-2006 10:54 AM
configure cisco pcmcia card on my laptop insurin Linux - Networking 1 02-04-2005 01:35 PM
I'm looking for a script to keep cisco vpnclient up and running cccc Linux - Networking 0 09-16-2003 04:09 PM
Using serial port to configure Cisco router rfc634 Linux - Networking 5 08-03-2003 10:41 AM
how to configure a linux firewall behind my cisco router totfc Linux - Security 0 06-01-2002 11:04 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Networking

All times are GMT -5. The time now is 11:37 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration