Batch file 窗口bat检查网站并重新启动coldfusion
我不熟悉蝙蝠脚本。我想在下面的脚本中检查web是否已启动,如果未启动,请重新启动coldfusion并将所有信息保存到日志文件中Batch file 窗口bat检查网站并重新启动coldfusion,batch-file,coldfusion,wget,Batch File,Coldfusion,Wget,我不熟悉蝙蝠脚本。我想在下面的脚本中检查web是否已启动,如果未启动,请重新启动coldfusion并将所有信息保存到日志文件中 @REM Remove any existing files. del C:\Users\Administrator\check.txt @REM to download file wget -O check.txt --no-check-certificate https://10.2.3.30/ebanking/ch/en-en/inde
@REM Remove any existing files.
del C:\Users\Administrator\check.txt
@REM to download file
wget -O check.txt --no-check-certificate https://10.2.3.30/ebanking/ch/en-en/index.cfm
@REM Search for the term in the previously downloaded file.
FINDSTR /C:"index.cfm" check.txt
if errorlevel equ 1 notfound
found
cls
:notfound
echo notfound > log.txt
echo stopping ebanking >> log.txt
call C:\ColdFusion10\cfusion\bin\cfstop.bat
echo starting ebanking >> log.txt
call C:\ColdFusion10\cfusion\bin\cfstart.bat
cls
exit
:found
echo found >> log.txt
cls
exit
您错过了标签
notfound
的goto
命令。对于逻辑,我在notfound/found之间交换了标签
@echo off
pushd "C:\Users\Administrator"
@REM Remove any existing files.
del check.txt
@REM to download file
wget -O check.txt --no-check-certificate https://10.2.3.30/ebanking/ch/en-en/index.cfm
@REM Search for the term in the previously downloaded file.
FINDSTR /C:"index.cfm" check.txt
if errorlevel equ 1 (goto notfound)
:found
echo found >> log.txt
exit /b 0
:notfound
echo notfound > log.txt
echo stopping ebanking >> log.txt
call C:\ColdFusion10\cfusion\bin\cfstop.bat
echo starting ebanking >> log.txt
call C:\ColdFusion10\cfusion\bin\cfstart.bat
exit
您可以在循环中将代码简化为以下内容
@echo off
set "someurl=https://10.2.3.30/ebanking/ch/en-en/index.cfm"
:loop
wget --server-response -nv --spider %someurl% 2>&1 | find "HTTP/1.1 200 OK">nul
if errorlevel 1 (
echo %DATE% %TIME%: stopping ebanking>> log.txt
call C:\ColdFusion10\cfusion\bin\cfstop.bat
timeout 5>nul
echo %DATE% %TIME%: starting ebanking>> log.txt
call C:\ColdFusion10\cfusion\bin\cfstart.bat
) else (
echo %DATE% %TIME%: site is up>> log.txt
)
rem Wait 1 hour before loop
timeout 3600
goto loop
您错过了标签
notfound
的goto
命令。对于逻辑,我在notfound/found之间交换了标签
@echo off
pushd "C:\Users\Administrator"
@REM Remove any existing files.
del check.txt
@REM to download file
wget -O check.txt --no-check-certificate https://10.2.3.30/ebanking/ch/en-en/index.cfm
@REM Search for the term in the previously downloaded file.
FINDSTR /C:"index.cfm" check.txt
if errorlevel equ 1 (goto notfound)
:found
echo found >> log.txt
exit /b 0
:notfound
echo notfound > log.txt
echo stopping ebanking >> log.txt
call C:\ColdFusion10\cfusion\bin\cfstop.bat
echo starting ebanking >> log.txt
call C:\ColdFusion10\cfusion\bin\cfstart.bat
exit
您可以在循环中将代码简化为以下内容
@echo off
set "someurl=https://10.2.3.30/ebanking/ch/en-en/index.cfm"
:loop
wget --server-response -nv --spider %someurl% 2>&1 | find "HTTP/1.1 200 OK">nul
if errorlevel 1 (
echo %DATE% %TIME%: stopping ebanking>> log.txt
call C:\ColdFusion10\cfusion\bin\cfstop.bat
timeout 5>nul
echo %DATE% %TIME%: starting ebanking>> log.txt
call C:\ColdFusion10\cfusion\bin\cfstart.bat
) else (
echo %DATE% %TIME%: site is up>> log.txt
)
rem Wait 1 hour before loop
timeout 3600
goto loop
除非您希望将此问题关闭为
不清楚您在问什么
编辑问题并指定问题所在并确保描述详细。除非您希望将此问题关闭为不清楚您在问什么
编辑问题并指定问题所在并确保描述详细。许多谢谢只需稍加调整,就能满足我的需要。非常感谢。只要稍加调整,它就能满足我的需要。