I'm trying to run an script to connect to a Procurve 4204vl switch using expect. This is the code I created:
#!/usr/bin/expect -f
set timeout 20
spawn ssh -l user 192.168.0.10
expect "[email protected]'s password:"
send "1234"
send "\r"
expect "Press any key to continue"
send "j\r"
send "conf"
send "\r"
send "no ip route 89.19.238.2 255.255.255.255 192.168.0.12"
send "\r"
send "exit"
send "\r"
send "exit"
send "\r"
send "exit"
send "\r"
expect "Do you want to log out [y/n]?"
send "y"
I run this using simply expect script.exp
, and the problem is I got these errors:
I got the following error on screen after the script execution is finished:
Press any key to continue invalid command name "y/n" while executing "y/n" invoked from within "expect "Do you want to log out [y/n]?"" (file "script.exp" line 19)
So, how could I solve this problem? Thank you.
PS: if I comment all the "exit"
lines and also the log out question, then add a last line with the "interact"
command, the script works fine.
For route not deleted, what output is the program giving you? Do you see any errors from the router?
In expect and Tcl the square brackets are the syntax to execute a command, quite like backticks in the shell. The simplest solution is to use braces instead of double quotes to prevent command interpolation:
expect {Do you want to log out [y/n]?}
Braces act like single quotes in the shell.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With