Checking files Changed date and email address if it has changed

I am looking for a bash script that will check if a file has been modified in the last hour, and send an email if it has been modified. This script will be used in Solaris and Ubuntu. I am sure this is not difficult, but I am not a Linux administrator. Can anybody help?

+4
source share
2 answers

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" spatel@example.com fi 

Put this script in an hourly cron job

 01 * * * * /path/to/myscript 
+9
source

linux supports the inotify command. You use it to track the activity of the file — change the file, create the file, whatever you want, whenever you want.

The specified find command will not work on a finished solarium. This is normal for Linux. You have two options in Solaris:

  • go to www.sunfreeware.com and download gnu coreutils, which will install gnu find (the above search version) to /usr/local/bin

  • write a script that uses the touch command, wait more than 60 minutes, then check the file, the only problem is that this script runs in the background forever, you can avoid this if you know some perl to generate a timestring suitable for touch -t [time string] , to create a file with a time of one hour in the past This is the version forever:

    and true

     do touch dummy sleep 3615 # 1 hour 15 seconds 

    [file_i_want_to_test -nt dummy] && & & echo 'file blah changed' | mailx -s 'file modified' me@myco.com

     done 
+1
source

All Articles