What I want to do is let my shell script stop when my python script, which is run by shell, exit unnormally. However I have to su to the ossadm to run the python script, how can I get the correct exit code when I su
Here is my code:
# shell script
su ossadm <<EOF
. /opt/oss/manager/bin/engr_profile.sh # which only can be executed by ossadm
python ${SRC_DIR}/main.pyc
echo $?
if [[ $? = 0 ]]; then
echo "success"
else
echo "failure: $?"
fi
EOF
# main.py
def main():
sys.exit(1) # for testing
then run the script, it always prints "0" and "suceess", or change the sequence:
su ossadm <<EOF
. /opt/oss/manager/bin/engr_profile.sh # which only can be executed by ossadm
python ${SRC_DIR}/main.pyc
EOF
echo $?
if [[ $? = 0 ]]; then
echo "success"
else
echo "failure: $?"
fi
# main.py
def main():
sys.exit(1) # for testing
This one will give me weirder "1" and "success".
Could this kind of processing could be done in shell script?
echo $?succeeds, so on the next line$?is 0.main.pycdirectly? The speedup (especially in this case) is negligible, and it won't reflect any changes you may make tomain.pywithout explicitly recompiling it.