Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Capturing Return Code On A Redirect

Status
Not open for further replies.
Jan 19, 2000
57
US
Hi!

When I redirect the output of a command to a file, how do I capture an error condition of the command? It seems that the script can only capture an error in the redirection of the output of the command, not an error with the command itself.

As an example:

If the following command is entered WITHOUT a redirect to a file:

dsmadmc -id=admin -pass=tunafish q vol
ANS8002I Highest return code was 137.

We receive an error code 137. This is good.

However, if the same command has a redirect:

dsmadmc -id=admin -pass=tunafish q vol > tunafish.txt

We get a return code of 0. This is a damnable lie! :)

Does anyone know of a way to intercept the error code before the redirect occurs?

Any advice would be most welcome.

Thanks!

Mikeymac

 
2>

Mike

"Whenever I dwell for any length of time on my own shortcomings, they gradually begin to seem mild, harmless, rather engaging little things, not at all like the staring defects in other people's characters."
 
or

smadmc -id=admin -pass=tunafish q vol ; RET_VAL=$? > tunafish.txt
echo $RET



Mike

"Whenever I dwell for any length of time on my own shortcomings, they gradually begin to seem mild, harmless, rather engaging little things, not at all like the staring defects in other people's characters."
 
Works on our TSM server (V5.5)...

[tt]# dsmadmc -server=myserver -id=admin -pass=gofish q vol
IBM Tivoli Storage Manager
Command Line Administrative Interface - Version 5, Release 5, Level 0.0
(c) Copyright by IBM Corporation and other(s) 1990, 2007. All Rights Reserved.

ANS1051I Invalid password
ANS1025E Session rejected: Authentication failure
ANS8023E Unable to establish session with server.

ANS8002I Highest return code was 137.
# echo $?
137

# dsmadmc -server=myserver -id=admin -pass=gofish q vol >/tmp/file
ANS1051I Invalid password
# echo $?
137

# dsmadmc -server=myserver -id=admin -pass=gofish q vol >/tmp/file 2>&1
# echo $?
137[/tt]


HTH,

p5wizard
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top