【发布时间】:2014-11-17 18:56:26
【问题描述】:
我正在使用带有监控标志的 autossh。每次发送测试数据包时,autossh 都会打印到标准输出。
在期望下使用 autossh 时,不会打印文本包消息。 我不知道它们是否已被发送,这对于保持 ssh 连接处于活动状态很重要。
你能判断“预期”是否会影响 autossh 行为吗? 如何判断 autossh 是否正常工作?
期望代码:
#!/usr/bin/expect
set timeout 50
spawn autossh -M 11111 -N -R 4848:localhost:80 user@192.168.1.100
set keepRunning 1
while {$keepRunning} {
expect \
{
"(yes/no)" { send "yes\r" }
"Password:*" { send "1234\r" ; set keepRunning 0 }
"ssh exited prematurely with" { exit 7 }
"remote port forwarding failed*" { exit 8 }
}
}
expect \
{
"remote port forwarding failed*" { exit 9 }
"Password:*" { exit 5 }
}
wait
我没有预料到的周期性输出是这样的:
autossh[2882]: checking for grace period, tries = 0
autossh[2882]: starting ssh (count 1)
autossh[2883]: execing /pfrm2.0/bin/ssh
autossh[2882]: ssh child pid is 2883
autossh[2882]: check on child 2883
autossh[2882]: set alarm for 50 secs
Password: autossh[2882]: connection ok
**autossh[2882]: check on child 2883
autossh[2882]: set alarm for 60 secs
autossh[2882]: connection ok
autossh[2882]: check on child 2883
autossh[2882]: set alarm for 60 secs**
最后5行是autossh发送的测试包。 仅当直接从 bash 运行 autossh 时才会打印这些行。 当使用“expect”运行时,这些行不会被打印出来,我不知道 autossh 是否发送它们。
谢谢。
【问题讨论】:
-
你能把你试过的代码贴出来吗?
-
我已经在原始消息中添加了代码。谢谢。