windows - How to Use IF Exist condition -


i have batch script check status of task running task scheduler , status of batch file , status of network load balancer.

my question :-

step-1:- want check status of task(health.bat) running in task scheduler if enabled or in ready status jump , check step-2

step-2:- here need check status of network load balancer(nlb) if in converged state jump , exit or else run -->health.bat-->if there no error --> start nlb or else-->send mail error message

issue code:-

the code running call health.bat jumps start nlb though health.bat fails :-

  @echo off setlocal enableextensions enabledelayedexpansion set itemail="mailid" /f "usebackq" %%i in (`hostname`) set host=%%i ::set host=%computername% set taskname1=health c: cd\ cd batch :: checking wscheck disabled schtasks.exe /query  /tn "%taskname1%" >checkts.txt 2>&1   findstr "running ready" checkts.txt if %errorlevel% neq 0 (  schtasks.exe /change /enable /tn "%taskname1%" >checkts.txt schtasks.exe /query  /tn "%taskname1%" >>checkts.txt wmailto %itemail% -s"the task health has been enabled on %host%." -tcheckts.txt ) :: checking if node stared nlb.exe query >checknlb.txt 2>&1 findstr /l /c:"converged" checknlb.txt if %errorlevel% neq 0 ( call wscheck.bat if exist findstr /l /c:"<--fail-->" health.txt (  wmailto %itemail% -s"down node %host% cannot started health failed." -thealthstatus.txt goto :exit ) else ( nlb.exe start >checknlb.txt timeout /t 10 nlb.exe query >>checknlb.txt wmailto %itemail% -s"the nlb has been started on %host%." -tchecknlb.txt ) )   :exit pause 

--->health.bat<---

@echo off setlocal enableextensions enabledelayedexpansion rem set  set itemail= "mailid"  pushd "c:\health" || goto :eof      set "tries=2"     /l %%a in (1 1 %tries%) (       >health.txt (             call pcheck.cmd             tester.exe -s parse          )         echo tester returned errorlevel : !errorlevel!          if not errorlevel 1 (             wmailto %itemail% -s"up -  health monitoring." -thealth.txt"             goto :eof         )         if %%a equ %tries% (            wmailto %itemail% -s"down -  health monitoring." -thealth.txt          )     ) 


Comments

Popular posts from this blog

resizing Telegram inline keyboard -

command line - How can a Python program background itself? -

php - "cURL error 28: Resolving timed out" on Wordpress on Azure App Service on Linux -