ADSM-L

Re: DOS Return-Code Primmer for PRECOMMAND and POST processing

2003-01-09 14:22:51
Subject: Re: DOS Return-Code Primmer for PRECOMMAND and POST processing
From: Andrew Raibeck <storman AT US.IBM DOT COM>
To: ADSM-L AT VM.MARIST DOT EDU
Date: Thu, 9 Jan 2003 12:21:57 -0700

>>
Does anyone have a URL or reference for me?  I need to use DOS batch files
to bring down and up an SQL database.
I have the batch file, but it is returning a 1 as a return code and that is
keeping the backups from occurring.
... TIA ... Jack

<<

Interesting that you ask, since I was just discussing this with someone else experiencing a similar problem.

While I don't know why you are getting the return code 1, you can put some debugging code into your script to help identify what is going on. Here is a sample that might serve as a template. It writes the messages to an output file so that you will be able to review the execution of the script.

IMPORTANT NOTE: My sample script assumes that return code 0 means success, and anything else means failure. Some commands may issue other (nonzero) return codes to indicate success. In such a case, your script will need to test for the valid return code(s) and behave accordingly. Because it is not possible for TSM to know what constitutes success for any given command, it establishes 0 to mean success and anything else to mean failure (a fairly standard convention). Thus, for example, if your particular command could issue a return code 3 to mean success, then you will have to test for this in your script; and if the return code is indeed 3, then you should treat it as a 0 so that TSM will know you mean success.

IMPORTANT NOTE: Watch for line wrapping in this text that I have no control over. I've tried to attach a plain text file (MyScript.txt, you'll need to rename to *.bat or *.cmd) as well, just in case.

Please let me know if you find this useful.


======================================================================
@echo off
set HIGHRC=0
set OUTFILE=C:\MyScript.txt


set SVC1="My Service #1"
set SVC2="My Service #2"
set SVC3="My Service #3"


if exist %OUTFILE% del %OUTFILE%



echo ---------------------------------------------------------------------- >> %OUTFILE% 2>&1
echo %date% %time% - Stopping %SVC1% >> %OUTFILE% 2>&1
echo ---------------------------------------------------------------------- >> %OUTFILE% 2>&1
net stop %SVC1% >> %OUTFILE% 2>&1
set LASTRC=%errorlevel%
if %LASTRC% gtr %HIGHRC% set HIGHRC=%LASTRC%


if %LASTRC% equ 0 (
  echo net stop for %SVC1% complete >> %OUTFILE% 2>&1
) else (
  echo net stop for %SVC1% failed, rc=%LASTRC% >> %OUTFILE% 2>&1
)




echo ---------------------------------------------------------------------- >> %OUTFILE% 2>&1
echo %date% %time% - Stopping %SVC2% >> %OUTFILE% 2>&1
echo ---------------------------------------------------------------------- >> %OUTFILE% 2>&1
net stop %SVC2% >> %OUTFILE% 2>&1
set LASTRC=%errorlevel%
if %LASTRC% gtr %HIGHRC% set HIGHRC=%LASTRC%


if %LASTRC% equ 0 (
  echo net stop for %SVC2% complete >> %OUTFILE% 2>&1
) else (
  echo net stop for %SVC2% failed, rc=%LASTRC% >> %OUTFILE% 2>&1
)




echo ---------------------------------------------------------------------- >> %OUTFILE% 2>&1
echo %date% %time% - Stopping %SVC3% >> %OUTFILE% 2>&1
echo ---------------------------------------------------------------------- >> %OUTFILE% 2>&1
net stop %SVC3% >> %OUTFILE% 2>&1
set LASTRC=%errorlevel%
if %LASTRC% gtr %HIGHRC% set HIGHRC=%LASTRC%


if %LASTRC% equ 0 (
  echo net stop for %SVC3% complete >> %OUTFILE% 2>&1
) else (
  echo net stop for %SVC3% failed, rc=%LASTRC% >> %OUTFILE% 2>&1
)




echo ---------------------------------------------------------------------- >> %OUTFILE% 2>&1
echo %date% %time% - exiting script with highest rc=%HIGHRC% >> %OUTFILE% 2>&1
echo ---------------------------------------------------------------------- >> %OUTFILE% 2>&1


exit %HIGHRC%
======================================================================



Regards,

Andy Raibeck
IBM Software Group
Tivoli Storage Manager Client Development
Internal Notes e-mail: Andrew Raibeck/Tucson/IBM@IBMUS
Internet e-mail: storman AT us.eyebm DOT com (change eye to i to reply)

The only dumb question is the one that goes unasked.
The command line is your friend.
"Good enough" is the enemy of excellence.



"Coats, Jack" <Jack.Coats AT BANKSTERLING DOT COM>
Sent by: "ADSM: Dist Stor Manager" <ADSM-L AT VM.MARIST DOT EDU>

01/09/2003 11:39
Please respond to "ADSM: Dist Stor Manager"

       
        To:        ADSM-L AT VM.MARIST DOT EDU
        cc:        
        Subject:        DOS Return-Code Primmer for PRECOMMAND and POST processing



Does anyone have a URL or reference for me?  I need to use DOS batch files
to bring down and up an SQL database.
I have the batch file, but it is returning a 1 as a return code and that is
keeping the backups from occurring.
... TIA ... Jack

Attachment: MyScript.txt
Description: Text document

<Prev in Thread] Current Thread [Next in Thread>