批处理脚本未按预期工作

时间:2017-11-26 17:03:49

标签: batch-file

我使用下面的脚本来测试我的网络服务超过一年,我最近发现,如果所有网络服务都失败,它就不会发送警报

case 1:- if all the service pass(logs.txt) it send the UP Alert
Case 2:- if one or two service got failed(logs.txt) it sends the down alert
but if all the service got failed(logs.txt) it didn't send any(Up or Down) alert
如果我有任何错误,请纠正我,现在这对我来说是个大问题

脚本: -

@echo on
setlocal enableextensions enabledelayedexpansion
REM set 
set mymail= "Superuser@gmail.com"   
pushd "c:\logs" || goto :eof

    set "tries=2"
    for /l %%a in (1 1 %tries%) do (
        >logs.txt (
            call resource.cmd
            Tester.exe  
        )
        echo The Tester returned errorlevel : !errorlevel! >>logs.txt
        if not errorlevel 1 (
            wmailto %mymail% -s"UP - WebServices Health Monitoring." -tlogs.txt"
            goto :eof
        )
        if %%a equ %tries% (
           wmailto %mymail% -s"DOWN - WebServices Health Monitoring." -tlogs.txt
        )
    )

logs.txt

CPU percentage: 0 %
Memory usage:   7 %

11/10/2017 1:25 PM

SOAP1 : <-- FAIL -->0.1249984 secs  
     Connection Error: Unable to connect to the remote server
SOAP2 : <-- FAIL -->0 secs  
     Unknown Exception: Object reference not set to an instance of an object.

XML1 : <-- FAIL -->0.015625 secs    
     Unknown Exception: Unable to connect to the remote server
XML2 : <-- FAIL -->0 secs   
     Unknown Exception: Unable to connect to the remote server

REST1 : <-- FAIL -->0.0156248 secs  
     Connection Error: Unable to connect to the remote server
REST2 : <-- FAIL -->0 secs  
     Connection Error: Unable to connect to the remote server
REST3 : <-- FAIL -->0 secs  
     Connection Error: Unable to connect to the remote server
REST4 : <-- FAIL -->0.0156247 secs  
     Connection Error: Unable to connect to the remote server
The Tester.exe returned errorlevel : 3 

带有更改的新脚本: -

@echo on
    setlocal enableextensions enabledelayedexpansion
    REM set 
    set mymail= "Superuser@gmail.com"   
    pushd "c:\logs" || goto :eof

        set "tries=2"
        for /l %%a in (1 1 %tries%) do (
            >logs.txt (
                call resource.cmd
                Tester.exe  
            )
            echo The Tester returned errorlevel : !errorlevel! >>logs.txt
            if not errorlevel 1 (
                wmailto %mymail% -s"UP - WebServices Health Monitoring." -tlogs.txt"
                goto :eof
            )
        )
        wmailto %mymail% -s"DOWN - WebServices Health Monitoring." -tlogs.txt

0 个答案:

没有答案