Help with finding the exit status of a 'nohup' command using 'PID'.


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Help with finding the exit status of a 'nohup' command using 'PID'.
# 1  
Old 09-18-2014
Help with finding the exit status of a 'nohup' command using 'PID'.

Hello All,

I need to run a set of scripts, say 50 of them, parallely. I'm running these 50 scripts, from inside a script with the help of 'nohup' command.

1.The fifty scripts are stored in a separate file.
2.In a master script, i'm reading every line of the file through loop and executing them.
3.The master script should succeed, if and only if, all the 50 scripts that has been called succeeds. Or else should fail.(Exit 0)

So far, this is what i have tried :

Code:
 
failcount=0
passcount=0
 
while read line; do
nohup sh $line &
PID=$(echo $!)
wait $PID
status=$(echo $?)

if [ $status -eq 100 ]
        then
        echo "Script FAILED." >> ${logfile}
        failcount=$((failcount+1))
elif [ $status -eq 0 ]
        then
        echo "Script SUCCEEDED." >> ${logfile}
        passcount=$((passcount+1))
fi
done < /$PATH/script.txt
 
if [ $failcount -gt 0 ]
        then
        echo "FAILURE!" >> ${logfile}
        exit 1
else
        echo "SUCCESS!" >> ${logfile}
        exit 0
fi

But this runs the scripts sequentially and NOT parallely. I need to start all the scripts parallely using nohup(or any other means if possible) and should be able to track their exit status individually.

Kindly help.

Cheers.

Last edited by vbe; 09-18-2014 at 09:44 AM..
# 2  
Old 09-18-2014
Quote:
But this runs the scripts sequentially and NOT parallely.
So why are you using wait $PID then?
# 3  
Old 09-18-2014
Quote:
Originally Posted by vbe
So why are you using wait $PID then?
I couldn't achieve parallelism. I could only do it sequentially(with help of wait). And thats why I came to you people for help.

Cheers.
# 4  
Old 09-18-2014
Well wait will for sure make your loop work in sequence since it will wait the end of execution of $PID...

With the logic you put in your script you wont be able to do anything else but sequential for you are to wait for end of execution to get the return code and if more processes are executed you have no means using $? to get what you want...

Last edited by vbe; 09-18-2014 at 11:40 AM.. Reason: typo...
# 5  
Old 09-18-2014
you can put the wait in another loop:

I would do:
Code:
while read line ; do
   nohup sh $line > $line.out 2>&1 &
   echo $! > $line.pid
done

for f in $(ls *.pid) ; do
   wait $(cat $f)
   echo ${f%.pid} exited with $?
done

otherwise you can make a wait between the 2 loop
and execute all your script with the time command:
Code:
/usr/bin/time -f "Elapsed %E, Exit Status %x" $line

time binary time can output the exit code.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Nohup Command gets status Stopped

Good Morning I need your help please, i tried to execute this script using nohup command but it gets in status stopped nohup ./SapInterfases.sh > SapInterfases.log & prodstg02$ jobs + Stopped(SIGTTOU) nohup ./SapInterfases.sh > SapInterfases.log & I check out log: $ more... (15 Replies)
Discussion started by: alexcol
15 Replies

2. Shell Programming and Scripting

Exit Status of Command

Hi All, I am doing an export and import (datapump) of 4 schema. I know we can do an export of 4 schema in one command. But just want to know how to check the exit status if i do the export/import of 4 schema in different commands in background. Please suggest. Thanks, Mani (1 Reply)
Discussion started by: pvmanikandan
1 Replies

3. SCO

PANIC: exit - cannot exec /etc/init (PID 1), status 0*00000200

Hi to all, I hope that you can help me with this... SCO Unix 5.0.5, old mashine Pentium III x86, SCSI HDD 36.4 Gb PANIC: exit – Cannot exec /etc/init (PID 1), status 0x00000200 Cannot dump 49055 pages to dumpdev hd (1/41) : space for only 48640 pages Dump not completed Safe to Power Off... (1 Reply)
Discussion started by: lakicevic
1 Replies

4. UNIX for Dummies Questions & Answers

Exit Status Of Find Command

Hello All, I am trying to capture the exit status of find command and want to delete the files only when it is successful. But it is always returning me as success even if the pattern of that file doesn't exist in the current directory. please help, checked manual page but couldn't able to figure... (6 Replies)
Discussion started by: Ariean
6 Replies

5. UNIX for Dummies Questions & Answers

Process status for NOHUP command

Hi, I have run a shell script as a background process using 'nohup' command. I want to see the process id of this, so that I will be able to kill it later on when required. I tried to collect these details using 'ps' command and could not view this information. How do we get this... (5 Replies)
Discussion started by: Dev_Dev
5 Replies

6. UNIX for Advanced & Expert Users

Equivalents of tee command to find exit status of command

Hi, Want to log the output of command & check the exit status to find whether it succeeded or failed. > ls abc ls: abc: No such file or directory > echo $? 1 > ls abc 2>&1 | tee log ls: abc: No such file or directory > echo $? 0 Tee commands changes my exit status to be always... (7 Replies)
Discussion started by: vibhor_agarwali
7 Replies

7. SCO

PANIC: exit - cannot exec /etc/init (PID 1), status 0*00000200.

hi all when ever i power on my sco server it give me the message:PANIC: exit - cannot exec /etc/init (PID 1), status 0*00000200. its not booting. any help?? (1 Reply)
Discussion started by: Danish
1 Replies

8. Shell Programming and Scripting

Move Command and exit status problem

Hi All, I am using the following code to move files from one folder to another on the remote server: ssh username@server <<EOF cd source_dir find . -type f -name "*.txt" |xargs -n1000 -i{} mv {} dest_dir if then send mail indicating error otherwise echo "success" fi EOF ... (10 Replies)
Discussion started by: visingha
10 Replies

9. Shell Programming and Scripting

Getting the exit status of a remote command

Hi to everyone. How can I get the exit status from a remote command executed with rexec? :eek: machine A has RedHat Linux 9 and the remote machine B has SCO UNIX. Code: rexec -l user -p password host sh /u/files/scripts/seq_cal.sh 2006 08 I want the exit status returned by... (1 Reply)
Discussion started by: zoonalex
1 Replies

10. UNIX for Dummies Questions & Answers

how to find the exit status for the last executed command

I am executing a find command in my script i.e find $2 -type f -name '*.gif' -mtime +$1 -exec rm {} \; how do i check that this command is executed properly.. i would lke t trap the errror and display my error message kinly help.. this is an urgent issue. (1 Reply)
Discussion started by: vijay.amirthraj
1 Replies
Login or Register to Ask a Question