Adding errorlevel to existing batch file

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
netwerkassist
Posts: 7
Joined: 21 Apr 2010 12:03

Adding errorlevel to existing batch file

#1 Post by netwerkassist » 21 Apr 2010 13:29

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.

Post Reply