Cisco Expect telnet scripts using different ports - TechRepublic
Question
March 14, 2015 at 09:40 PM
garris_b2000

Cisco Expect telnet scripts using different ports

by garris_b2000 . Updated 11 years, 2 months ago

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 discussion is locked

All Comments