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...

# 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 ""
# Main loop
foreach device $devices {
spawn telnet $device ### I know the $port goes here but how for each router####
sleep 1
expect "'^]'.
send "\n"

{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!"
expect eof

This conversation is currently closed to new comments.

Thread display: Collapse - | Expand +

All Answers

Share your knowledge

Related Discussions

Related Forums