网上的使用 BAT 脚本批处理都好像有一些问题,我发一个亲测可用的!!!
测试了半天好像没啥问题!在别人基础上改了一下!
-
@echo off
-
::守护程序-沙箱自动化平台
-
rem 定义循环间隔时间和监测的服务:
-
-
-
set _task=v.exe
-
set _svr="%cd%\%_task%"
-
set _des=start.bat
-
-
echo.
-
echo ========================================
-
echo == 查询沙箱测试平台服务的状态, ==
-
echo == 每间隔10秒进行一次查询, ==
-
echo == 如发现其停止,则立即启动。 ==
-
echo == AE博客 ==
-
echo ========================================
-
echo.
-
echo 此脚本监测的服务是:%_task%
-
echo.
-
-
-
:checkstart
-
for /f "tokens=5" %%n in ('qprocess.exe ^| find "%_task%" ') do (
-
if %%n==%_task% (goto checkag) else goto startsvr
-
)
-
-
:startsvr
-
echo %time%
-
echo ********程序开始启动********
-
echo 程序重新启动于 %time% ,请检查系统日志 >> restart_service.log
-
echo cd %_svr% > %_des%
-
echo start %_task% >> %_des%
-
echo exit >> %_des%
-
start %_des%
-
set/p=.<nul
-
for /L %%i in (1 1 10) do set /p a=.<nul&ping.exe /n 2 127.0.0.1>nul
-
echo .
-
echo Wscript.Sleep WScript.Arguments(0) >%tmp%\delay.vbs
-
cscript //b //nologo %tmp%\delay.vbs 10000
-
del %_des% /Q
-
-
echo ********程序启动完成********
-
goto checkstart
-
-
:checkag
-
echo %time% 程序运行正常,10秒后继续检查..
-
echo Wscript.Sleep WScript.Arguments(0) >%tmp%\delay.vbs
-
cscript //b //nologo %tmp%\delay.vbs 10000
-
-
goto checkstart