Recently, my wamp crashed and restarted inexplicably, apache can automatically get up, but mysql is a tragedy.
So there is the following batch file for monitoring and starting the wamp service
@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 > null 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 > null goto chkit :end
The key command is for /F "tokens=1* delims= " %%a in ('net start') do if /I "%%a" == %srvname1% set svrst1=1
For a detailed explanation of the For command, please refer to: Basic usage of the for statement under dos and in batch processing