I am writing some wait commands in bash.
Script:
#!/bin/bash
set timeout -1
expect -c "
spawn telnet $IP $PORT1
sleep 1
send \"\r\"
send \"\r\"
expect Prompt1>
interact timeout 20 {
sleep 1
}
expect {
Prompt2> {send \"dir\r\" }
}
"
My intentions with the script are to connect telnet to the computer first, when it sees Prompt1, let it give me control, I will execute a command to download a specific image. Then wait for Prompt2 to appear (which indicates that the image has been downloaded). Then let him execute a further set of commands.
After running the script, I can enter interactive mode, upload the image. The problem is to exit interactive mode on the remote computer and return to it.
The error I received is:
expect: spawn id exp4 not open
while executing
"expect -nobrace Prompt2 {send "dir\r" }"
invoked from within
"expect {
Prompt2 {send "dir\r" }
}"
How can i do this?
source
share