Welcome guest. Before posting on our computer help forum, you must register. Click here it's easy and free.

Author Topic: Need to create an alert after the 2 conditions are met in the batch file  (Read 2578 times)

0 Members and 1 Guest are viewing this topic.

salism0b

    Topic Starter


    Starter

    :START
    set PRDDIR=c:\windows\system32\dns      
    set BCKDIR=%PRDDIR%\backup    
    set SCSFULDIR=%PRDDIR%\successful.log   
    set UPDDIR=%PRDDIR%\update         
    set LOGDIR=%PRDDIR%\log         
    set DNSLOG=%LOGDIR%\update_dns.log      
    set BOOT=%PRDDIR%\Boot-Files         

    REM Check for new zone files in update directory
    If not exist %UPDDIR%\db.* goto END_UPDATE     
    del %SCSFULDIR%\* /Q >nul   
    REM Time stamp DNS log file      
    date/T >> %DNSLOG%            
    time/T >> %DNSLOG%            


    REM Stop DNS process
    net stop dns                  
    if errorlevel 1 goto STOP_ERROR   ----- REM NEED ALERT         

    REM Backup existing zone files         
    copy %PRDDIR%\*.* %BCKDIR% >nul      
    REM Copy in new zone files
    copy %UPDDIR%\*.* %PRDDIR% >nul      
    copy %BOOT%\*.* %PRDDIR% >nul      
    set TRY=1                  

    :RESTART_DNS               
                         
    REM Restart DNS process
    net start dns                  
    if not errorlevel 1 goto RESTART_OK      

    If %TRY%==2 goto RESTART_ERROR   NEED  alert has to be triggered-----☻


    REM Recover backed up zone files   
    copy %BCKDIR%\*.* %PRDDIR% >nul
    copy %BOOT%\*.* %PRDDIR% >nul      
    set TRY=2                  
    goto RESTART_DNS               
    pause

    :STOP_ERROR

    echo DNS stop FAILED >> %DNSLOG%      
    goto END_UPDATE               

    :RESTART_ERROR

    echo DNS restart FAILED >> %DNSLOG%   
    goto END_UPDATE   

    :RESTART_OK

    REM Remove new zone files from update directory
    If %TRY%==1 del %UPDDIR%\* /Q >nul       rem Update successful ☺

    If %TRY%==1 echo DNS restart SUCCESSFUL >> %DNSLOG%   

    If %TRY%==1 echo DNS restart SUCCESSFUL > % SCSFULDIR %   
    If %TRY%==2 echo DNS restart RECOVERED >> %DNSLOG%

    :END_UPDATE

    The idea to add the successful. log is to create another batch file to run in unification and check for a file in the path. If the file is missing then we need to trigger an alert so total there are 3 instances of alert.

    I need the syntax to create the batch file which will look for the file successful.log and if not exist send the net send command to the list of ppl identified by their login accounts

    Sidewinder



      Guru

      Thanked: 139
    • Experience: Familiar
    • OS: Windows 10
    Re: Need to create an alert after the 2 conditions are met in the batch file
    « Reply #1 on: January 26, 2009, 05:49:57 AM »
    Code: [Select]
    if not exist %SCSFULDIR% net send user "message text"

    Replace user and "message text" as appropriate. You can also use the msg command if you prefer.

    Not sure why you need the exist test. Does not entering STOP_ERROR or RESTART_ERROR indicate an error?

    Good luck. 8)
    The true sign of intelligence is not knowledge but imagination.

    -- Albert Einstein

    salism0b

      Topic Starter


      Starter

      Re: Need to create an alert after the 2 conditions are met in the batch file
      « Reply #2 on: January 27, 2009, 01:52:04 AM »
      I tried using netsend but it checks for name resolution and is not able to resolve the user. It only recognizes user logged on to the machine. Though net send with machine name is possible. the exist command is an error indication but it doenst send any alert. this file is being run on a remote server so i dont monitor the machine.

      Just want to verify if error level 1 is correct command? and what does the "copy %BOOT%\*.* %PRDDIR% >nul"        do?