Reputation: 12522
I have a following script for executing commands on a remote device over ssh:
#!/usr/bin/expect -f
set cmd $argv
set timeout -1
spawn ssh -p22 [email protected]
match_max 100000
expect "*?assword:*"
send "PASS\r"
expect "<*"
send $cmd\r
expect "* :"
send "Y\r"
expect feof
At the last line, my script is expecting "end of file" in order to exit. However the remote device never sends "end of file" even though the communication is over. Is there a possibility to exit on some sort of inactivity timer? Something like:
expect feof for 10 seconds
Upvotes: 1
Views: 194
Reputation: 247072
use eof
not feof
set the timeout
variable before the last expect:
send "Y\r"
set timeout 10
expect {
timeout {
send_user "no EOF after $timeout seconds"
exp_close
}
eof
}
wait
Upvotes: 2