Question

Locked

Cisco Expect telnet scripts using different ports

By garris_b2000 ·
I'm a newbie at this...I'm trying to write an expect script that telnet to multiple routers on ports different on each router. My problem is how to assign each specific port to the correct router... Any help you can give on that plus this script would be greatly appreciated...

#!/usr/bin/expect
# Define User, Pass, and Ports
set username "cisco"
set password "1234"
set port1 2100
set port2 2200
set port3 2300
set port4 2400

# Define all the devices to be configured (separated by spaces)
set devices "172.16.1.1 172.16.1.2 172.16.1.3 172.16.1.4"
# Main loop
foreach device $devices {
spawn telnet $device ### I know the $port goes here but how for each router####
sleep 1
expect "'^]'.
send "\n"
{expect

"login:"
{send "$username\n"
expect "word:"
send "$password\n"
}
"#"
{ send "config t\n"
expect "(config)#"
send "end\n"
expect "#"
send "exit\r"
}

"host: Connection refused"
{
send_user "ERROR:EXITING!"
exit
}
expect eof
}
}

This conversation is currently closed to new comments.

2 total posts (Page 1 of 1)  
| Thread display: Collapse - | Expand +

All Answers

Share your knowledge
Back to Software Forum
2 total posts (Page 1 of 1)  

Related Discussions

Related Forums