近日发现云服务器上的 wamp 莫名其妙的崩溃重启,apache 能自动起来, 却悲剧了。
于是有了下面的wamp服务监控和启动的批处理文件
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 | @ 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 语句的基本用法