bat实现守护程序保证平台正常运行
1.systeminfo查看系统最近一次重启时间:
2.杀进程:
:start
taskkill /f /im "xx.exe"
goto start
"xx.exe"是你需要关系的进程的名称,如果名称中带空格,就必须用两个英文的双引号括起来。
3.守护线程
::守护程序-沙箱自动化平台
rem 定义循环间隔时间和监测的服务:
set secs=30
set srvname="notepad.exe"
@echo off
echo.
echo ========================================
echo == 查询沙箱测试平台服务的状态, ==
echo == 每间隔%secs%分种进行一次查询, ==
echo == 如发现其停止,则立即启动。 ==
echo ========================================
echo.
echo 此脚本监测的服务是:%srvname%
echo.
tasklist -v | findstr %srvname% > NUL
if ErrorLevel 1 (
echo "========================================">>E:\bat\temp\keepAliveLog.txt
echo %date%+ %time% ">>当前进程不存在" >> E:\bat\temp\keepAliveLog.txt
::echo %date%+ %time% >> E:\bat\temp\keepAliveLog.txt
echo "开始启动">> E:\bat\temp\keepAliveLog.txt
e:
cd bat\
app.bat
echo "执行成功" >> E:\bat\temp\keepAliveLog.txt
echo "========================================">>E:\bat\temp\keepAliveLog.txt
) else (
echo %date%+ %time% "进程存在">> E:\bat\temp\keepAliveLog.txt
)