Link to home
Start Free TrialLog in
Avatar of ratna1234
ratna1234

asked on

Shell Script

ls -lrt MMMM_APPS.log

MMMM_APPS.log

Based on last log file time if the log file is not updated more than 30 min , i need to send an mail that "Log file is no updated past 30 Min".
Avatar of Thankxx
Thankxx
Flag of United States of America image

Hi,
put this following code in a file and save it like :/home/ratna/mmmm_alert.sh
Script start:

#!/usr/bin/sh

current=`date +%s`
last_modified=`stat -c "%Y" $file`

if [ $(($current-$last_modified)) -gt 1800 ]; then
    echo "Log file is no updated past 30 Min" | mail -s "MMMM_APPS.log not updated" <desired mail address>
else
     exit
fi
------------------------------------------------------
Now add this file to crontab for run every 30 min -
0,30 * * * * /home/ratna/mmmm_alert.sh

Thankxx

Avatar of Tintin
Tintin

What *nix flavour will this be running on?
Avatar of ratna1234

ASKER

Its Linux
ASKER CERTIFIED SOLUTION
Avatar of Tintin
Tintin

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Hi,
In my code 4th line $file is the full path of file MMMM_APPS.log.
Anyway let us know the update.

Thankxx