LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - General (https://www.linuxquestions.org/questions/linux-general-1/)
-   -   Cisco, Telnet, and Bash Scripting (https://www.linuxquestions.org/questions/linux-general-1/cisco-telnet-and-bash-scripting-547658/)

gss6 04-20-2007 01:51 PM

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.

MensaWater 04-20-2007 02:10 PM

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

gss6 04-20-2007 02:21 PM

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?


All times are GMT -5. The time now is 05:50 PM.