./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....
is there any command or a way in which I can parallely check the abc process within 123.sh?
Hi Scott...Thanks a lot for ur help..but you know I am in a fix again
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.