need to know status from "su -c"

Hi,

I am executing a script as root user which needs to do something as oracle user.

So I have following in my script:

 
#!/bin/sh
..........
..........
su - oracle -c "export ORACLE_SID=MYSID; cd /global/home/orasql/$ORACLE_SID; ./doSomething.sh"
if [ $? -ne 0 ]; then
 echo "Error running doSomething.sh" 
fi

If doSomething.sh returns an error, my echo stmt does not execute (maybe because su succeeds). How do I make it execute? Thanks.

How about...

su - oracle -c "export ORACLE_SID=MYSID; cd /global/home/orasql/$ORACLE_SID; ./doSomething.sh; [ $? -ne 0 ] &&  echo 'Error running doSomething.sh' " 

That works :slight_smile:

Preferably I want status code so that I can exit from the main script depending on the status code.

Thanks again.

Trying writing the status to a file in the child script and processing it back in the parent...

su - oracle -c "export ORACLE_SID=MYSID; cd /global/home/orasql/$ORACLE_SID; ./doSomething.sh; echo $? > /tmp/doSomething.stat "
if [ `cat /tmp/doSomething.stat` -ne 0 ]; then
 echo "Error running doSomething.sh" 
fi
rm /tmp/doSomething.stat

Jerry

Actually the following works well:

 
su - oracle -c "/global/home/orasql/MYSID/doSomething.sh"

if [ $? -ne 0 ]; then
echo "Error running doSomething.sh" 
fi

I can now get status from doSomething.sh w/o any problem. Thanks.