How to capture exit code for a bg job


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers How to capture exit code for a bg job
# 1  
Old 11-12-2008
How to capture exit code for a bg job

If I execute a job in background (in ksh or bash), how would I capture the exit code for that job?

Thanks,

- CB
# 2  
Old 11-15-2008
Code:
#! /usr/bin/ksh


false &
pid=$!
wait $pid
result=$?
echo result of false is $result

true &
pid=$!
wait $pid
result=$?
echo result of true is $result
exit 0
$
$
$ ./back
result of false is 1
result of true is 0
$

 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to capture the exit code of a shell script in a perl script.?

hi, i want to pop up an alert box using perl script. my requirement is. i am using a html page which calls a perl script. this perl script calls a shell script.. after the shell script ends its execution, i am using exit 0 to terminate the shell script successfully and exit 1 to terminate the... (3 Replies)
Discussion started by: Little
3 Replies

2. Shell Programming and Scripting

How to capture exit code of child script and send it to parent script?

#!/usr/local/bin/bash set -vx /prod/HotelierLinks/palaceLink/bin/PalacefilesWait /prod/HotelierLinks/palaceLink/bin/prodEnvSetup 03212013 & if then echo "fatal error: Palace/HardRock failed!!!!" 1>&2 echo "Palace Failed" | mail -s "Link Failed at Palace/HardRock" -c... (1 Reply)
Discussion started by: aroragaurav.84
1 Replies

3. Shell Programming and Scripting

How to capture script return code?

Hi I am executing database backup via shell script (Korn). The backup log is long, but I would like to capture only the last line so I can send an email if it fails Example of failed backup (only last 3 lines) BR0056I End of database backup: bejbofoh.aff 2012-07-26 07.31.21 BR0280I... (7 Replies)
Discussion started by: nimo
7 Replies

4. Shell Programming and Scripting

Comparing files and capture return code

Hi, I would like to compare 2 files, and have a return code write to a file. regardless of the files contents are the same the code should be writing to a file (if both files contents are same then return code 0). A simple example will be great :) Thanks (3 Replies)
Discussion started by: khchong
3 Replies

5. Shell Programming and Scripting

Exit Shell Script with background job

Hi all, I am trying to exit a shell script (c shell) while invoking a job (service) that must run in the background: ...... /mydir/runservice & exit ...... There are downstream jobs and scripts that need to be run, but they all 'wait' for the script to exit. The script 'hangs' and... (3 Replies)
Discussion started by: CKT_newbie88
3 Replies

6. UNIX for Dummies Questions & Answers

nohup - sub job in script not executing until I exit

My job is launched using this command: I'm at home and having VPN drops so I used nohup and background. nohup perf_mon -c rating_4_multi,cfg & The main script is PID 26119, and the sub task under it is 26118 which is not running - just sits there. 26119 runs forever but nothing else runs. I... (2 Replies)
Discussion started by: ido1957
2 Replies

7. Shell Programming and Scripting

Capture unexpected exit in shell script

Hi, I have shell script that checks processes forever. But somehow it is killed and I want to know what causes it. while do check the processes if they are running, if not restart them done I want to capture the output when the script is terminated, how can I do that? /Andreas (2 Replies)
Discussion started by: mr_andrew
2 Replies

8. Programming

how to capture OS name using C/C++ code

Hi, I want to know the os name via c/c++ source code.so please help me to do the same. I will appreciate if anyone can provide me the source code. Thanks in advance.. (9 Replies)
Discussion started by: smartgupta
9 Replies

9. Shell Programming and Scripting

How to capture status code and echo a message

Im trying to execute application and its return code is below IF Status code=o echo "........" else Staus Code =-2 DJRE then echo "......" Can any one help me how to handle the status code and echo some message. (12 Replies)
Discussion started by: laknar
12 Replies

10. UNIX for Dummies Questions & Answers

Where can I find a list of exit codes? (Exit code 64)

I'm receiving an exit code 64 in our batch scheduler (BMC product control-m) executing a PERL script on UX-HP. Can you tell me where I can find a list of exit codes and their meaning. I'm assuming the exit code is from the Unix operating system not PERL. (3 Replies)
Discussion started by: jkuchar747
3 Replies
Login or Register to Ask a Question