Shell script task status monitoring
Posted
by Bikram Agarwal
on Stack Overflow
See other posts from Stack Overflow
or by Bikram Agarwal
Published on 2010-05-19T07:46:11Z
Indexed on
2010/05/19
7:50 UTC
Read the original article
Hit count: 305
I'm running an ANT task in background and checking in 60 second intervals whether that task is complete or not. If it is not, every 60 seconds, a message should be displayed on screen - "Deploy process is still running. $slept seconds since deploy started", where $slept is 60, 120, 180 n so on.
There's a limit of 1200 seconds, after which the script will show the log via 'ant log' command and ask the user whether to continue. If the user chooses to continue, 300 seconds are added to the time limit and the process repeats.
The code that I am using for this task is -
ant deploy &
limit=1200
deploy_check()
{
while [ ${slept:-0} -le $limit ]; do
sleep 60 && slept=`expr ${slept:-0} + 60`
if [ $$ = "`ps -o ppid= -p $!`" ]; then
echo "Deploy process is still running. $slept seconds since deploy started."
else
wait $! && echo "Application ${New_App_Name} deployed successfully" || echo "Deployment of ${New_App_Name} failed"
break
fi
done
}
deploy_check
if [ $$ = "`ps -o ppid= -p $!`" ]; then
echo "Deploy process did not finish in $slept seconds. Here's the log."
ant log
echo "Do you want to kill the process? Press Ctrl+C to kill. Press Enter to continue."
read log
limit=`expr ${limit} + 300`
deploy_check
fi
Now, the problem is - this code is not working. This looks like a perfectly good code and yet, this is not working. Can anyone point out what is wrong with this code, please.
© Stack Overflow or respective owner