LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
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.

Notices

Reply
 
Search this Thread
Old 04-20-2007, 01:51 PM   #1
gss6
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 (disconnect.sh and connect.sh) 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.

Code:
#switches.conf
# Syntax is <Room> <IP> <Port to shutdown>
Room1 192.168.1.1 FastEthernet0/1
Room2 192.168.1.2 FastEthernet0/2
Room3 192.168.1.3 FastEthernet0/3
So that when I type ./disconnect Room3 it will telnet to 192.168.1.3 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
MensaWater
Guru
 
Registered: May 2005
Location: Atlanta Georgia USA
Distribution: Redhat (RHEL), CentOS, Fedora, Debian, FreeBSD, HP-UX, Solaris, SCO
Posts: 5,972
Blog Entries: 5

Rep: Reputation: 777Reputation: 777Reputation: 777Reputation: 777Reputation: 777Reputation: 777Reputation: 777
Save this as something like "switch.sh"

Code:
#!/bin/bash
ROOM=$1

set `grep $ROOM switches.conf`
IP=$2
PORT=$3

# 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 switch.sh).

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

Original Poster
Rep: Reputation: 0
Code:
#!/bin/bash

ROOM=$1

set `grep $ROOM switches.conf`
HOST=$2
IP=$3
PORT=$4

# 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': "
read 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.
 
  


Reply

Tags
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 02:02 AM.

Main Menu
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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration