Welcome to the most active Linux Forum on the web.
Go Back > Forums > Linux Forums > Linux - General
User Name
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.


  Search this Thread
Old 04-20-2007, 01:51 PM   #1
LQ Newbie
Registered: Jul 2006
Posts: 2

Rep: Reputation: 0
Cisco, Telnet, and Bash Scripting

I'm a cisco guy, and I know linux very well, just not bash scripting. What I need is a script ( and that will telnet into a switch and disable a port given an arguement.

So if type disconnect room16, it will go into a text file (switches.conf) and look for the given argument and load the ip to telnet to, and the port to shutdown.

The layout of the text file should look something like this, maybe tab delineated.

# Syntax is <Room> <IP> <Port to shutdown>
Room1 FastEthernet0/1
Room2 FastEthernet0/2
Room3 FastEthernet0/3
So that when I type ./disconnect Room3 it will telnet to and shutdown FastEthernet0/3 on the switch.

Now I know I need to use the expect command once I invoke telnet, but I haven't even gotten the above to work.
Old 04-20-2007, 02:10 PM   #2
LQ Guru
Registered: May 2005
Location: Atlanta Georgia USA
Distribution: Redhat (RHEL), CentOS, Fedora, CoreOS, Debian, FreeBSD, HP-UX, Solaris, SCO
Posts: 6,818
Blog Entries: 14

Rep: Reputation: 1076Reputation: 1076Reputation: 1076Reputation: 1076Reputation: 1076Reputation: 1076Reputation: 1076Reputation: 1076
Save this as something like ""


set `grep $ROOM switches.conf`

# Echoing values just to be sure we have the right ones
echo Room is $ROOM
echo IP is $IP
echo PORT is $PORT

# Uncomment the below to telnet to the IP - you need to build your
# expect around this - I'm not an expect person at all.
# telnet $IP
Make executable (e.g. chmod 744

Run it: Room1
Old 04-20-2007, 02:21 PM   #3
LQ Newbie
Registered: Jul 2006
Posts: 2

Original Poster
Rep: Reputation: 0


set `grep $ROOM switches.conf`

# Echoing values just to be sure we have the right ones
echo Room is $ROOM
echo IP is $IP
echo PORT is $PORT

echo -n "What is the console password for this device? 'AUTH': "
read AUTH
echo -n "What is the enable password for this device? 'ENABLE': "
That's what i have so far, any idea on the expect stuff?

Last edited by gss6; 04-25-2007 at 01:23 PM.


bash, cisco, scripting, telnet

Thread Tools Search this Thread
Search this Thread:

Advanced Search

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

Similar Threads
Thread Thread Starter Forum Replies Last Post
scripting telnet sessions, redirect issue farkus888 Solaris / OpenSolaris 4 03-03-2007 02:18 PM
help bash scripting sh4d0w13 Linux - Newbie 5 08-15-2005 02:02 AM
bash scripting fnoyan Programming 1 01-18-2005 07:35 AM
BASH Scripting ? eroica Programming 3 06-07-2004 07:51 PM
Telnet into Cisco router via /dev/ttyS0 (aka COM1 serial port) naesyllek Linux - Networking 2 06-25-2003 05:33 PM

All times are GMT -5. The time now is 04:50 AM.

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