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

Background job completion status back to parent shell

Status
Not open for further replies.

oerrora

IS-IT--Management
Nov 21, 2001
4
US
We have some shell scripts in whihc we submit 10 different shell scripts or C executables in background mode. Whether they fail or not, the mail script always returns success. We are not able to find out when one of the job fails unless we go and look at the logs for that individual.
EX:
main.sh
contains..
prog1.sh&
cexe &
prog2.sh&
prog3.sh&
.
.
.
Is there any better way we can handle in such a way that, after any of those submitted (background mode) jobs fail, it should return the status back to main program and let the main program to fail.

Thanks for your help.,


 
How about a script to check the logs for failures?

Or have a wrapper script for each script/program.
Run the wrapper in the background
which runs the script/program in the foreground
and returns shell status to the wrapper script
and pages if necessary.

Robert Robert G. Jordan

Robert@JORDAN2000.com
Unix Sys Admin
Chicago, Illinois U.S.A.
[lightsaber]
 
One way is to echo the exit status of the script to a file. Then check the file contents to find out the program's exit status. Here's an example:
Code:
(prog1.sh; echo $? > $FILE)&
...
wait
STATUS=`cat $FILE`
 
Sounds like you need the return code returned to auto secure. I haven't worked with auto secure, but here's a suggestion.

Setup the jobs individualy in autoesecure and do not run them in the background.

The return code is 0 because the execution
of your background job was successful.

try running these commands and see what happens
abc_xyz;echo "STATUS: $?" &
(abc_xyz &);echo "STATUS: $?" Robert G. Jordan

Robert@JORDAN2000.com
Unix Sys Admin
Chicago, Illinois U.S.A.
[lightsaber]
 
The programs in main are run in background.

prog1.sh can not give main.sh a value when it is
not finished.
because of the background jobs main.sh will be ready in an
instant.

main.sh :

prog1.sh
if [ $? –ne 0 ] ;then
ret = 1
fi
cexe
if [ $? –ne 0 ] ;then
ret=`expr $ret + 2`
fi
prog2.sh
if [ $? –ne 0 ] ;then
ret=`expr $ret + 4`
fi
prog3.sh
if [ $? –ne 0 ] ;then
ret=`expr $ret + 8`
fi


This way main is finished when the last in batch is finished.

Then you can: echo $ret |mail –sreturn_value to_yourself.

Regards Gregor
Gregor.Weertman@mailcity.com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top