2015-11-04 77 views
1

我是蝙蝠腳本的新手。我想要下面的腳本來檢查網絡是否啓動,如果不重新啓動coldfusion並將所有信息保存到日誌文件中。窗口蝙蝠檢查網站並重新啓動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/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 
+2

除非你想這個問題,關閉爲'不清楚你在做什麼問'編輯問題,並指定什麼是問題,並確保描述是詳細的。 – wOxxOm

回答

0

您的標籤notfound錯過goto命令。對於邏輯,我換NOTFOUND之間標籤/發現

@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 
+0

非常感謝。幾乎沒有調整,它滿足了我的需求。 – Drsin