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

exit codes 1

Status
Not open for further replies.

ahernandez

Technical User
Aug 14, 2001
3
US
Hello everyone,

I have two questions regarding exit codes. Using the following command as an example:

rsh remote_server ddate

will give an exit value of '0'. Is there a way to check the exit code of the command that is performed on the remote machine ?

Also, I am using /usr/sbin/ufsdump in a script, with a ' |tee -a $LOGFILE ' piped to the end of it in order to get the standard output sent to a logfile. The value of $? will only give me the exit code of the 'tee' command. Is there any way to get the exit code of the 'ufsdump' AND keep using 'tee' ?

I know that if I run the command without the 'tee' extension, I can get a proper exit status. Is there a way to keep the tee piece and STILL be able to get an exit code from the ufsdump part ?

Thank you to anyone who can help or explain why this is impossible.

Thanks

Alan Hernandez
arhernandez@imcglobal.com



 
I would recommend using re-direction instead of a pipe. You can re-direct STDN out and STND error to the same file, and your exit code will report "correctly". For example:

# mkdir test
# cd test
# ls -l
total 0
# touch test.out
# ls -l
total 0
-rw-r--r-- 1 root system 0 Nov 02 07:50 test.out
# ls -l >> test.out 2>&1
# cat test.out
total 0
-rw-r--r-- 1 root system 0 Nov 02 07:50 test.out
# ddate >> test.out 2>&1
# echo $?
127
# cat test.out
total 0
-rw-r--r-- 1 root system 0 Nov 02 07:50 test.out
bash: ddate: command not found
#

crowe
 
A solution to your problem :

{
/usr/sbin/ufsdump ...
echo "dumpsts=$?" > /tmp/sts.$$
} | tee -a $LOGFILE
teests=$?
. /tmp/sts.$$
echo "Ufsdump status = $dumpsts"
echo "Tee status = $teests"


Jean Pierre
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top