windows下的脚本:
需要固定时间间隔比如5秒运行一个文件,网上查了下最简单的就是用goto语句,如果不加延时那就是死循环,在里面加上延时语句choice /t 5 /d y /n >nul。下面的批处理作用就是每隔5秒监测ngrok进程是否存在,存在不做任何处理,不存在就启动另外脚本。括号里面的是注释
:start
choice /t 5 /d y /n >nul (5秒执行一次下面的指令)
tasklist|find /i "ngrok.exe" (检查是否存在ngrok.exe进程,如果检测到,下面比较的值为0,为0表示存在。)
if %errorlevel%==0 (
echo "yes"
) else (
echo "No"
start startup.bat (新窗口启动startup.bat脚本)
)
goto start (循环)
linux下的脚本:
#!/bin/sh
while true;do
count=`ps -ef|grep node|grep -v grep`
if [ "$?" != "0" ];then
echo "wdt is running"
./wdt 5
else
echo "wdt is stop..."
break
fi
sleep 3
done