Hi,
I have a scipt that telnets to a machine (DSLAM) and then telnet again to a local IP of that machine (aDSL module) and retrieves its uptime.
Here it is:
Code:
#!/bin/bash
MSAN_IP=$1
SLOT_IP=$2
ARGS=2
if [ $# -ne $ARGS ]; then
echo "`basename $0`: Wrong number or parameter supplied"
echo "`basename $0`: Usage: `basename $0` <MSAN_IP> <SLOT_LOCAL_IP>"
exit 0;
else
expect << EOF
set timeout 3
spawn telnet $MSAN_IP 2323
expect "IPCP login: "
send "root\r"
expect "Password: "
send "E/SOu53r\r"
expect "~ # "
send "telnet 10.1.3.$SLOT_IP\r" # HERE LIES THE PROBLEM
expect "60xADSL login: "
send "root\r"
expect "Password: "
send "weblin1\r"
expect "60xADSL# "
send "uptime\r"
expect "60xADSL# "
send "exit\r"
expect “~ # ”
send "exit\r"
exit
EOF
fi
There is a problem with it...
if the second telnet to the aDSL module is not successful (e.g. unreachable module), the script will continue although the phrase it expects "60xADSL login: ", will never appear. So instead of the aDSL module uptime, the script will give me the uptime of the DSLAM machine.
To give you a visual aid these are the steps (when everything is ok):
Code:
[portal@preproduction ~]$ telnet 10.193.2.19 2323
Trying 10.193.2.19...
Connected to 10.193.2.19.
Escape character is '^]'.
You are logging into Marconi IP Common Part "IPCP"
IPCP login: root
Password:
~ # telnet 10.1.3.12
Entering character mode
Escape character is '^]'.
Linux 2.4.20_mvl31-wds-mips_fp_be (60xADSL) (0)
60xADSL login: root
Password:
this is motd file to inform any information to user
BusyBox v1.00-rc2 (2004.08.03-10:23+0000) Built-in shell (ash)
Enter 'help' for a list of built-in commands.
60xADSL# uptime
01:14:33 up 145 days, 2:53, load average: 0.00, 0.00, 0.00
when the aDSL module is unreachable:
Code:
[portal@preproduction ~]$ telnet 10.193.2.19 2323
Trying 10.193.2.19...
Connected to 10.193.2.19.
Escape character is '^]'.
You are logging into Marconi IP Common Part "IPCP"
IPCP login: root
Password:
~ # telnet 10.1.3.10
telnet: Unable to connect to remote host (10.1.3.10): No route to host
~ # uptime
01:22:17 up 343 days, 15:50, load average: 0.02, 0.20, 0.17
Well, what I need is to know when the second telnet is successful or not.
Any ideas please?
thank you in advance.