重置expect的超时定时器,同时从send命令接收输出

问题描述 投票:0回答:1

是否可以在发出“send”的命令打印输出时重置超时定时器?

情况是我想在许多服务器上运行像find / -exec head {} /;这样的命令。我希望在命令打印输出时重置计时器。我不喜欢将超时设置为小时...

谢谢!

expect
1个回答
2
投票

使用exp_continue,这是可能的。

set threshold 1
set timeout 60; # 1 min
send "find / -exec head {} / \r"
expect {
    # Your prompt here
    "#"; {puts "prompt matched. cmd completed"}
    timeout {
        # Checking for max of 10 mins 
        if {$threshold>10} {
            puts "output took more time than threshold"
            exit 1
        }
        incr threshold
        puts "Still waiting for the prompt"
        # The below command will reset the expect timer 
        # and will cause the same expect loop to run again
        exp_contintue;
    }
}
© www.soinside.com 2019 - 2024. All rights reserved.