Page 1 of 1

Adding errorlevel to existing batch file

Posted: 21 Apr 2010 13:29
by netwerkassist
I'm new to adding errorlevel logic into a batch file and looking for some help.

The script I have runs a few SQL commands via OSQL and want to be notifyied if one step fails (for one reason or another) and echo out the issue into a file and email me.

@echo on
:Step 1
: Call Backup_Database.bat to shutdown PS environment
c:
CD c:\scripts\HR83RPT
ECHO Backing Database
CALL Backup_Database.bat
PAUSE

:Step 3
:use osql to kill any active user sessions
CD c:\scripts\HR83RPT
osql -S ZVMPSESQL01 -U sa -P squamish -i c:\scripts\HR83RPT\uspkill.txt >> c:\scripts\HR83RPT\HR83RPT_refresh.txt
echo User sessions have been terminated
PAUSE

:Step 4
:use isql command to kick off refresh executing refresh script
CD c:\scripts\HR83RPT
echo Refreshing Database
isql -S ZVMPSESQL01 -U sa -P squamish -i c:\scripts\HR83RPT\HR83RPT.sql >> c:\scripts\HR83RPT\HR83RPT_refresh.txt
echo Database Refreshed

echo %Date% %Time% >> c:\scripts\HR83RPT\HR83RPT_refresh.txt
PAUSE

:Step 6
:Send Refresh log
CD c:\scripts\hr83rpt
echo Sending Refresh log file
CALL Refresh_Log.cmd

:error

Refresh_Log.cmd above sends a list of all actions performed and mails out to me.

Appreciate replies.