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 :

 
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.

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.

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

you can put the wait in another loop:

I would do:

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:

/usr/bin/time -f "Elapsed %E, Exit Status %x" $line

time binary time can output the exit code.