I'm writing a script that will automate the launch of some services on my AIX machine. However, some services are dependent on the successful startup of others. When I start these services manually, I usually just check a log file until I see a message that confirms a successful startup. So, I figure I can integrate this into my script but I'm not sure what the best way to do it is. I was thinking something like this:
while [ `tail -f /path/to/log/file | grep "PATTERN"` -ne "0" ]; do
done
but that seems cumbersome for the system (not to mention the fact that I don't think it's working). What would be the best approach here? Thanks for your help.
Well, I would do that except for it's possible for the process to start up unhealthily (couldn't think of another word). This means that the process is alive but not functioning the way it's supposed to. In order for me to check if the process is alive and healthy, I have to check the log file. Also, it takes ~20 secs for the process to come up completely so I feel like the checking has to be done in a loop; I can't just check once and then move on.
Here's an example to check log as the server starts and look for a WORD to confirm a start of Service. Here's I am looking for word 'RUNNING' in the log every 10 seconds and when found, I am coming out of the loop.
#!/bin/ksh
while [ 1=2 ]; do
grep RUNNING /opt/logs/Server.log>a.txt
if [ -s a.txt ]
then
echo "Found RUNNING"
exit 0
fi
echo 'checking Server.log for status RUNNING every 10 seconds until completed'
sleep 10
done