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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

tee command leads to false return codes

Status
Not open for further replies.

hfaix

MIS
Nov 25, 2003
596
US
I currently have a front-end built in kornshell for operators to kick of regular mksysb’s for me. Inside the script I use a fairly common mksysb command (via sudo):

#*** called via kornshell script ***
/usr/local/bin/sudo mksysb -ie /dev/rmt0
RC=$?

Recently, I’ve noticed it would be nice to have logs of what actually happened during the mksysb. I wanted to have the stdout go to the screen and to a log file. Seems simple, right?

I planned on using :
/usr/local/bin/sudo mksysb -ie /dev/rmt0 | tee –a /mydir/myfile.log
RC=$?

However, the RC is actually the RC from the tee command, not from mksysb. This isn’t what I’m looking for. I need the RC to instruct the operator on what to do next.

I’ve tried - unsuccessfully:

MAKEBKUP()
{
/usr/local/bin/sudo mksysb -ie /dev/rmt0 | tee –a /mydir/myfile.log
RC=$?
}

MAKEBKUP | tee –a /mydir/myfile.log

Sorry this got so long, but I’m certain someone has come across this….Any ideas?
 
E-mail me - I'll send you a mksysb script I created that does all this.

bverzal@komatsuna.com
 
Does anyone else have an idea? Bjverzal provided me with a "different" approach to it, which I may have consider, however, I'd really like to get this to work as described.

Thanks again for your help bjverzal.
 
Because the 'tee' command is a separate process and is run after the previous command, it will provide the final result code. I personally ran into this today with a script I was working on.

BV
 
Hi,

This workaround may do the job
The idea is to do the job in two steps :

1) run mksysb and print its exit status in the same shell instance : eg surrounded by parentheses, in which you print a tag containing the exit status and redirect the result of this shell to your log file .
2) grep for the mksysb exit status tag in the logfile and process it to get the info.
In this example, I choose "mksysb_rc :" as tag


( /usr/local/bin/sudo mksysb -ie /dev/rmt0 ;RC=$?; print "mksysb_rc : $RC" )|tee –a /mydir/myfile.log

MKSYSB_RC=$(grep mksysb_rc /mydir/myfile.log|awk -F: '{print $2}'|sed -e 's/ //g' )

# At this point MKSYSB_RC contains the exit status of mksysb
if [ "$MKSYSB_RC" = "0" ]
then
.....

See the parentheses (/usr ..... and ) |tee ....


Ali


 
Since it would also be nice to know what your script instructed your operator to do next, why not create a wrapper script that binds stderr to stdout and captures all of the output of your current script?

Code:
#!/bin/ksh

/usr/local/bin/currentmksysbscript 2>&1 | tee mksysb.log

This wouldn't require any changes to your current script, although you might want to echo any user input explicity if you aren't already, so the operator's selections will also be logged.

Rod Knowlton
IBM Certified Advanced Technical Expert pSeries and AIX 5L

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top