I'm writing a script with expect
to configure cisco routers automatically via ssh
.
A part of this script is to copy an image into flash
if it doesn't exist:
For this expect sends a copy
and waits for Destination filename
then sends a return
.
cisco#copy tftp://10.xx.xx.3/name_of_image.bin flash:
Destination filename [name_of_image.bin]?
Now there're two options:
- The File doesn't exist and gets copied into
flash:
- The File exists and the script skips this part.
If the file already exists it looks like this:
%Warning:There is a file already existing with this name
Do you want to over write? [confirm]
Now to my problem:
The scripts waits for Do you want to over write? [confirm]
and then should exit since the image is already in flash.
But currently it seems like expect
can't recognize that line and gets stuck at the confirmation. It've tried several patterns like [confirm]
, *[confirm]*
, Do
, *write*
and some more.
My code for that job looks like this at the moment:
expect "*#"
send "copy tftp://10.$ip_local.3/name_of_image.bin flash:\r"
expect "Destination filename"
send "\r"
expect {
"Do you want to over write? [confirm]"{
interact
abort
}
expect "*#"
send "exit\r"
What am I doing wrong?