0

我有批处理文件,我在其中重新启动机器并想检查机器是否重新联机,然后在特定时间后执行代码块,否则通知用户机器不在线我想检查以下内容:

pingresult = ping \\machinename

if (pingresult == true)
{
  execute some task
}
else
{
   keep  pinging for say 5min. if after 5mins machine is not up show message to user
}
4

1 回答 1

2

这将尝试 ping %machinename% 100 次,默认超时时间为 3 秒:3s * 100 = 300s,即 5 分钟。

for /L %%N IN (1, 1, 100) DO (
    ping -n 1 %machinename%
    if not ERRORLEVEL 1 (
        set pingresult=true
        goto done
    )
)
set pingresult=false
:done
if %pingresult% == true (
  echo "ping ok, doing something..."
) else (
  echo "no reply after 5 mins, error!"
)
于 2013-07-30T13:03:21.097 回答