开发者

expect: exit on no action from programs' side

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 USER@192.168.1.1
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 commu开发者_StackOverflow社区nication is over. Is there a possibility to exit on some sort of inactivity timer? Something like:

expect feof for 10 seconds


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
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜