Please help with monitoring stuff

Hi,

I am trying to write a script to do monitoring kind of stuff,

requirement - when a server is given a start it updates a file called server.log, I need to keep on grepping the word "Running" and as soon as it comes , script should be exited with the message , "Server came up successfully else it shoud wait for "Running" untill 7 minuts, and then should time out with the message "script timed out"

My idea is to use tail -f server.log | grep "Running" , but im not sure how will this exit because tail will wait for the input into server.log

for timinig out I think best I can use is sleep

so it shoud be

 
while ( i < 420 )
do 
   tail -f server.log | grep "Running"   //(the problematic area)
   if [ $? == 0 ]
    then   
           echo "Server came up succesfully"
           exit 0
i++
done
echo "script timed out"

PLease suggest. if my logic is wrong or i have placed wrong commands.

Hi,

if you are not sure when the server will be started then you can write two scripts, first one will check if server is started or not. Then place this script into crontab and set its check (running) period according to your requirements and your system performance; lets say 15 seconds everyday, or 1 day of month or one day of every week etc.. Then add a conditional part into the first script so that you can trigger the second script with grep part.

lets say:

if [ -e  "/LOGS/applications_backup/output.txt" ]; then ##server start log##
cd scripts_directory
./log_check_script
else
echo "server not started"
exit 0
fi

Thanks Eagle, It was a great idea, But unfortunetly we dont hav root access.:frowning: