Since the OP was asking about exit status's in regards to child processes... I thought I would add this.
Consider two shell scripts, parent and child:
PARENT (test-parent.sh):
Code:
#!/bin/sh
# bash and ksh will expand '$?' to be the exit status of the previous command
# we can use that to get a child scripts exit status
# If you have many child processes and they are running
# in parallel you will want to look into the trap statement.
# trap will allow you to get info back from the child using something like
# trap "command to run on trap" CHLD
# where CHLD is the exit status of the child process
echo "I am the parent script."
echo
echo "I am now calling the child script..."
echo
echo "###############################################"
./test-child.sh
XSTAT=$?
echo "###############################################"
echo
echo "We have now obtained the exit status of the child (exit status: ${XSTAT})."
echo "We can determine what to do (exit with bad exit code or live on)."
echo
if [ "${XSTAT}" -gt 0 ]; then
echo "Bad exit from child... exiting."
exit ${XSTAT}
else
echo "The child exited gracefully with exit status '${XSTAT}'"
echo "We can now proceed doing other tasks as usual."
fi
echo "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"
echo "Weeeeeee other tasks."
exit ${XSTAT}
CHILD(test-child.sh):
Code:
#!/bin/sh
echo "I am the child script."
echo -n "What would you like my exit status to be: "
read XSTAT
echo "Exiting with exit status: ${XSTAT}"; exit ${XSTAT}
Now see the output when run...
BAD EXIT STATUS (not 0)
Code:
[user@host ~]$ ./test-parent.sh
I am the parent script.
I am now calling the child script...
###############################################
I am the child script.
What would you like my exit status to be: 3
Exiting with exit status: 3
###############################################
We have now obtained the exit status of the child (exit status: 3).
We can determine what to do (exit with bad exit code or live on).
Bad exit from child... exiting.
GOOD EXIT STATUS (0)
Code:
[user@host ~]$ ./test-parent.sh
I am the parent script.
I am now calling the child script...
###############################################
I am the child script.
What would you like my exit status to be: 0
Exiting with exit status: 0
###############################################
We have now obtained the exit status of the child (exit status: 0).
We can determine what to do (exit with bad exit code or live on).
The child exited gracefully with exit status '0'
We can now proceed doing other tasks as usual.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Weeeeeee other tasks.
Hi Guys,
I was just wondering if anybody can help me with this problem.
OK, how we can get a value back from PL/SQL Script (not stored procedure/function)
See the below example: (for example aaa.sh)
#!/bin/ksh
VALUE=`sqlplus -s user/password@test_id <<EOF
@xxx.sq
EOF`
echo $VALUE
... (7 Replies)
How to find out whether the command I executed is successful or unsuccessful(at commandlinet)
Eg:
say i execute the following command at command line
rm *
How do i find out whether my previous command is a success or failure.
Thankyou.
Best Regards,
Ram. (1 Reply)
hi all
my system is linux red hat
i have a script that runs some object .
the object return some code to the system
i see the code by writing echo $?
i want to ask in the script if $? equals 14
how shell is do that in the script
thanks (3 Replies)
Hi All,
Can anyone please let me know the syntax / how to pick up the Return Code ( RC) from the mailx command and return it to SAS uisng 'system()' function and '${?}'.
I am in a process to send the mail automatically with an attachment to bulk users. I have used 'Mailx' and 'Unencode'... (0 Replies)
Hi Guys,,
I am having a unix script which is running the DB2 Insert command.
For the insert command, there were no records to be updated.
SQL0100W No row was found for FETCH, UPDATE or DELETE; or the result of a
query is an empty table. SQLSTATE=02000
+ + echo 1
STAGE_RC=1
+ ]
... (6 Replies)
Hello folks,
I have a question that if i type ls command and type echo $? it always show "0", how i could do this change that when i type ls it will show me 1, actually i want to change the return code of commands from 0 to 1.
Thanks
Bash (5 Replies)
Hi
I'm writing a shell script that connects to oracle database and fires query to check the availability of data in a table. In case of no data found then what will be the return code and how to handle in that in variable. Kindly provide with an example for better understanding... Thanks... (1 Reply)
Folks -
Firstly, I do apologize that my first post here is a question. I am quite familiar with UNIX since our application is running on it. We are trying to automate a few things on our end and I am challenged with a task in hand that requires UNIX scripting. I am totally a newbie in UNIX... (4 Replies)
Hello,
I am woring on a script where I am getting strange situation.This script actually fetch the source code and tar that code and send to NAS location.This code resides in MKS tool...and we are fetching the source code on checkpoint label basis and script is working fine.First it synch the... (0 Replies)
I am using mutt on ksh Unix to send emails to addresses plucked from the database. If the "To:" email address is not longer valid and so the email is not sent to the "To:" recipient, but is sent to the valid cc address, I need to be able to get an error code returned to the shell script so that... (3 Replies)