Operating System - HP-UX
1834086 Members
2629 Online
110063 Solutions
New Discussion

Which status am I seeing?

 
SOLVED
Go to solution
Don Spare
Regular Advisor

Which status am I seeing?

I have a script that does a daily export of my Oracle databases thru a pipe to compress (they are too large otherwise). In the script I check for status of the command and if not 0 I send myself an e-mail saying that something did not work right. Anyway, today I received such an e-mail but I can find nothing wrong with last night's export. The command I am using is:

echo $sys_id/$sys_passwd | exp parfile=$PARFILE >> ${EXP_LOG_DEST}/${EXP_LOG_FILE} 2>&1
status=$?

Then I check the value of 'status' to determine whether or not to send e-mail. So I guess my question is: Which part of the piped command am I getting the status of?

Any help is greatly appreciated.
4 REPLIES 4
Jeff Machols
Esteemed Contributor
Solution

Re: Which status am I seeing?

Don,

you are checking the status of echo, the $? will give you the result of the outermost (left) command
Don Spare
Regular Advisor

Re: Which status am I seeing?

That's what I was afraid of. Thanks for the input.
A. Clay Stephenson
Acclaimed Contributor

Re: Which status am I seeing?

Hi Don:

The answer is that of the last command in the pipeline - exp. The problem is that many commands don't play by the rules. I know that svrmgrl and sqlplus do not; I suspect that exp does not as well. Many Oracle commands (and other applications as well) return 0 as long as they exited gracefully. You really need to examine stdout/stderr and look for patterns to do want you want.

Clay
If it ain't broke, I can fix that.
A. Clay Stephenson
Acclaimed Contributor

Re: Which status am I seeing?

Jeff didn't quite get this correct. Let's do a simple test:

echo "XX" | grep -q "YY"
echo $?
That should be 1 - no matches found by grep

echo "XX" | grep -q "XX"
echo $?
That will return 0 - 1 or more matches found by grep
If it ain't broke, I can fix that.