Check a files Modified date and email if it has changed

SueS picture SueS · Jan 4, 2013 · Viewed 9.3k times · Source

I am look for a bash script that will check if a file has been modified in the last hour and email an alert if it has been modified. This script will be used in Solaris and Ubuntu. I am sure it's not hard, but I am not a Linux admin. Can someone please help?

Answer

Satish picture Satish · Jan 4, 2013

How about this?

#!/bin/bash

[[ -z `find /home/spatel/ -mmin -60` ]]

if [ $? -eq 0 ]
then
    echo -e "nothing has changed"
else
    mail -s "file has been changed" [email protected]
fi

Put this script in hourly cron job

01 * * * * /path/to/myscript