Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I'm not an expert in writing shell scripts but also I'm looking for a very specific solution.

OS: CentOS release 5.2 (Final)

I've a Java standalone which keeps writing (all System.out.println) to a log file. For some unknown reason, this Java standalone stops working at some point of time in my server and eventually logs writing also stops working.

I want to have a script which checks the last modified date & time of the log file with current date & time in the server. If the time difference exceeds more than 5 minutes, I want to send an email immediately to my recipients list. This way I'll come to know when this Java standalone has stopped working.

I'll move this script to crontab and make it run for every 1 minute, so that this whole process is automated.

Log file location: /usr/local/logs/standalone.log

share|improve this question
1  
this is more likely to get a good answer on stackoverflow.com –  cpbills May 13 '10 at 6:07
add comment

1 Answer

up vote 2 down vote accepted

however, i was bored... something like:

#!/bin/sh

SUBJECT="blah is more than 5 minutes old!"
EMAIL="email@example.com"
MSG="/tmp/emailmessage"

MOD=`stat --printf=%Y $1`
NOW=`date +%s`
DIFF=$(($NOW-$MOD))
if [ $DIFF > 300 ]; then
    echo "$1 is more than 5 minutes old!" > $MSG
    mail -s "$SUBJECT" "$EMAIL" < $MSG
fi
share|improve this answer
    
Where is the file location /usr/local/logs/standalone.log passed to in the above script? –  Gnanam May 13 '10 at 6:46
    
@Gnanam: It's the first command line argument ($1). –  vwegert May 13 '10 at 7:53
    
@vwegert Thanks. It's working perfectly. –  Gnanam May 13 '10 at 10:03
    
i think $DIFF > 300 should be $DIFF -gt 300 i was a little tired when writing this –  cpbills May 13 '10 at 16:04
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.