作者:LY萍 | 来源:互联网 | 2023-10-13 10:28
近日我的wamp莫名其妙的崩溃重启,apache能自动起来,mysql却悲剧了。于是有了下面的wamp服务监控和启动的批处理文件@echooffremdefine
近日我的 wamp 莫名其妙的崩溃重启,apache 能自动起来, mysql 却悲剧了。
于是有了下面的wamp服务监控和启动的批处理文件
@echo off
rem define loop time
set secs=5
set srvname1="wampapache64"
set srvname2="wampmysqld64"
echo.
echo ==========================================================
echo == Query Services Status Every %secs% second
echo == Auto Start Services : %srvname1%, %srvname2%
echo ==========================================================
echo Detecting ...
if %srvname1%. == . goto end
if %srvname2%. == . goto end
:chkit
set svrst1=0
for /F "tokens=1* delims= " %%a in ('net start') do if /I "%%a" == %srvname1% set svrst1=1
if %svrst1% == 0 echo %date%-%time%
if %svrst1% == 0 net start %srvname1%
set svrst1=
ping -n %secs% 127.0.0.1 > nul
set svrst2=0
for /F "tokens=1* delims= " %%a in ('net start') do if /I "%%a" == %srvname2% set svrst2=1
if %svrst2% == 0 echo %date%-%time%
if %svrst2% == 0 net start %srvname2%
set svrst2=
ping -n %secs% 127.0.0.1 > nul
goto chkit
:end
关键的命令是 for /F "tokens=1* delims= " %%a in ('net start') do if /I "%%a" == %srvname1% set svrst1=1
详细的 For 命令解说,可参考 : dos下 和 批处理中的 for 语句的基本用法