How to monitor a shell script called within a script?

HIi Guys... I am in a fix.... 1st the code :

Script 123.sh looks like this :

./abc # a script which is getting called in this script
while true
do
     count=`ps -ef | grep abc | wc -l`
     if [ $count -gt 1]
     echo "abc is running
     sleep 10
     fi
done

but the process is getting checked only after ./abc is getting finished.... :frowning:

is there any command or a way in which I can parallely check the abc process within 123.sh?

Please help me out!!!!

Maybe you want to run "abc" in the background:

./abc &

Hi Scott

So if I try running it in background shall it work?..Can you provide me the script?

./abc &
while :; do
  jobs %1 2> /dev/null >&2 || break
  echo "abc is running..."
  sleep 5
done
1 Like

Hi Scott...Thanks a lot for ur help..but you know I am in a fix again :frowning:

nohup ./processProv.sh &
while true
do
count=`ps -ef | grep processProv | wc -l`
if [ $count -gt 1 ]
            echo "Process is running (Process Prov)
            er=`grep -i Error processProv.log | wc -l` #a log where I need to  check   error generated or not parallely along with this#
                   if [ $er -ge 2 ]
                       echo "Error found " 
                       exit 1
                   fi
fi
sleep 5
done

.....but it is getting stuck after the main process (nohup ./processProv.sh &) is getting complete(maybe because of sleep 5 command)...can you please suggest an alternate code so that the : process running + error check is also validated as long as the main script runs?...processProv.log is the log which gets creates once ./processProv.sh starts...

You never leave the loop unless you find an error. Either use the break command as Scott demonstrated or use a different loop.

#!/bin/bash
nohup ./processProv.sh &
PID=$!
while ps -p $PID >/dev/null 2>&1; do
   echo "Process is running (Process Prov)
   er=`grep -i Error processProv.log | wc -l` #a log where I need to check error generated or not parallely along with this#
   if [ $er -ge 2 ]
      echo "Error found "
      exit 1
   fi
   sleep 5
done

Edit: Scotts check is more robust - on very busy systems you may find another process than the background process if process numbers warped.