Capture unexpected exit in shell script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Capture unexpected exit in shell script
# 1  
Old 02-24-2010
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 [ true ]
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  
Old 02-24-2010
Code:
#/bin/sh
while true; do
    count=`ps aux |grep "your process" | grep -v "grep"`
    if [ "$?" != "0" ]; then
        do something
    else
        do something
    fi
done


Last edited by Franklin52; 02-24-2010 at 10:41 AM.. Reason: Reformatting indentation
# 3  
Old 02-24-2010
Here is very cpu friendly process. Sleep in wait cmd until child process get some signal.
Code:
#!/bin/someposixsh
outf=/tmp/$0.$$.tmp"
echo "$0 PID:$$ started $(date '+%Y%m%d %H%M%S')" >> $outf
while true 
do
     subprocess >> $outf 2>&1    &
     subpid=$!
     echo "Started ChildPid:$subpid"  
     wait $subpid
     echo "$0 PID:$$ child $subpid has problem $(date '+%Y%m%d %H%M%S')"  >> $outf
     echo "child has got some signal" >> $outf  
done

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Capture run time of python script executed inside shell script

I have bash shell script which is internally calling python script.I would like to know how long python is taking to execute.I am not allowed to do changes in python script.Please note i need to know execution time of python script which is getting executed inside shell .I need to store execution... (2 Replies)
Discussion started by: Adfire
2 Replies

2. Shell Programming and Scripting

Shell Script to Capture a Screenshot

Hi All, Suppose I want to take a screenshot of a website say Google and save that image. How should I do it? I tried wget with this but of no help. It just makes a particular file in jpeg format but on opening the same it says corrupted. Although I can edit the jpeg as an HTML file. wget... (15 Replies)
Discussion started by: ankur328
15 Replies

3. 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

4. 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

5. Shell Programming and Scripting

shell script - unexpected result

I hv a file --am executing a script which is giving me unexpected results COntents of file: f1 CMT_AP1_CONT:/opt/sybase/syboc125:150:ASE12_5::Y:UX: CMT_AP1:/opt/sybase/syboc125:150:ASE12_5::Y:UX f1.tmp CMT_AP1_CONT:/opt/sybase/syboc125:150:ASE12_5::Y:UX:... (2 Replies)
Discussion started by: rajashekar.y
2 Replies

6. Shell Programming and Scripting

Capture makefile errors in shell script

Hi, I have a bash script which calls a few "make". I would like to know whether the makefile failed with any errors. How do I do that in the script? Thanks, S (2 Replies)
Discussion started by: suryaemlinux
2 Replies

7. Shell Programming and Scripting

`(' unexpected error when running a shell script in AIX

Hi, We are moving from linux to AIX servers, and as a result testing our scripts on the new platform. When I run one of our scripts, I get the following error message: ./branchDataUpdate.sh: syntax error at line 21 : `(' unexpected Following is an extract from the script: ...... ........ (1 Reply)
Discussion started by: dawgfather80
1 Replies

8. Shell Programming and Scripting

Capture Shell Script Output To A File

Hi, I am running a shell script called dbProcess.sh which performs shutdown and startup of various Oracle instances we have.At the time of execution the script produces the following output to the command line window $./dbProcess.sh stop #### Run Details ###### Hostname : server-hop-1... (4 Replies)
Discussion started by: rajan_san
4 Replies

9. UNIX for Dummies Questions & Answers

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 (1 Reply)
Discussion started by: ChicagoBlues
1 Replies

10. HP-UX

unexpected exit

On top of that, there is another question met on HP-UX 11i v2. The running program exit unnormally and no coredump. I used the 'gdb' tool to debug , it exit and return the message: (gdb) ttrace wait: No child processes. When using 'where' to find the breakpoint, it retruned... (0 Replies)
Discussion started by: Frank2004
0 Replies
Login or Register to Ask a Question