如果当前plink会话超时并自动重新连接,我如何创建一个简单的批处理脚本(Windows)来关闭它?
就像这样:
if "plink.exe" == "false" (
"plink command to connect to SSH Server."
)或者也许
如果"plink.exe“== "false”(“批处理打开新的plink实例”)
发布于 2013-04-16 16:50:43
这就是你要的。
@echo off
setlocal
:: modify this line as appropriate
set plink_args=-P 22 -i c:\path\to\private.ppk user@host
set errors=0
:loop
:: if "find" exits with a non-zero status, plink.exe isn't running.
( tasklist /fi "IMAGENAME eq plink.exe" | find /i "plink.exe" >NUL && (
set errors=0
) ) || (
start "" plink.exe %plink_args%
set /a "errors+=1"
)
if %errors% geq 5 (
echo Unable to connect %errors% times in a row. Stopping.
goto :EOF
)
:: pause for 10 seconds (-n seconds + 1)
ping -n 11 0.0.0.0 >NUL
goto loop您知道,如果您在ssh服务器上具有根访问权限,您可以修改sshd_config,并让服务器每隔几分钟发送一次无操作数据包,以防止连接因不活动而超时。下面是我的sshd_config的一个示例片段
# noop anti-idle for 12 hours (10 minutes * 72)
ClientAliveInterval 600
ClientAliveCountMax 72将其添加到您的sshd_config并重新启动ssh守护进程。这样你就不用在客户端做那么麻烦的事了。
https://stackoverflow.com/questions/16028107
复制相似问题