|
The error was due to the fact that Cisco router/switch doesn't not accept any command that is not Cisco's such "found prompt, sending command:..." and also Mathewg42's suggested code seems to have a missing the EOF to ensure the script is not terminated too early. Below is my suggested script, it is for ssh (tested and worked fine with Solaris). However, you can modify it to support telnet session (just take extra care with the prompt as telnet may ask for the userid and password more than once).
(solaris)$ cat test.exp
#!/usr/local/bin/expect
#Written by ThemHuyen. Date 27/04/2012
#
#
#
set timeout 20
set pwd "your_passwd_goes_here"
set file [open target.txt r]
set ip_list [split [read $file] "\n"]
close $file
foreach host $ip_list {
if {$host != ""} {
spawn ssh -o StrictHostKeyChecking=no $host
expect {
"ssword:" { send "$pwd\r" }
}
set load_cmd [open "commands.txt" r]
set cmd_list [split [read $load_cmd] "\n"]
close $load_cmd
expect {
{#} { foreach command $cmd_list {
if {$command != ""} {
send "$command\n"
}
}
}
}
expect EOF
}
}
########################
(solaris)$ cat commands.txt
show ip int brief
show int sum
show clock
exit
########################
(solaris)$ cat target.txt
10.10.10.10
11.11.11.11
12.12.12.12
13.13.13.13
########################
|