Dec 20

Hi it has been along time since my last blog, i found this usefull script on this forum http://forums.asmallorange.com/topic/13649-shell-script-to-monitor-file-changes/. I just want to share it 🙂

just go to your shell and create scan.sh files

# vim scan.sh

and type this

####################################################################################################################

#!/bin/bash

#Directory to search
myDir=/home/username/public_html

#Set frequency of command in minutes, this should match how often you run the cron job
myFrequency=’-30′

#email address for mailing the results
myEmail=email@address.com

#Create datestamp for subject line
#This makes each subject line unique to prevent message collapsing in Gmail
myDate=`date +%y-%m-%d`
myTime=`date +%H:%M`

#Test if files have been edited
fileCount=`find $myDir -mmin $myFrequency -type f | wc -l`
if [ $fileCount -gt 0 ]
then
#Write the subject line and set correct form of the word “files” (singular or plural)
if [ $fileCount -eq 1 ]
then
mySubject=”Attention! $fileCount File Modified on $myDate at $myTime”
else
mySubject=”Attention! $fileCount Files Modified on $myDate at $myTime”
fi

#execute find command and email the results
find $myDir -mmin $myFrequency -type f | mail -s “$mySubject” $myEmail
#else nothing happens
fi

####################################################################################################################

then save it chmod 755 and run it (./scan.sh)

or you can create crontab to run every 30 minute

# crontab -e

*/30 * * * * /root/scan.sh