Monitor file changes in your Website

This script can be used to notify you when a file changed in your website. This is useful when you want to know when a file changed or your site is hacked and you to monitor your site for file changes so you know when hacker upload or modify a file.

First you need to add your web site to GIT.

This can be with

Replace /var/www/html with actual DocumentRoot for your web site.

Every time you modify or add a file, you need to commit it to git you will get alerted. You can commit a new file to git with command

Create a file

Add following content

In the script, replace /var/www/html with actual document root of your web site. Change email and site name with your email and domain name.

Set following cronjob.

Cronjob will run every 1 hour and email you if any file change is detected. You can modify cronjob if you want to monitor more frequently, every 1 hour will be fine for most uses.

If you have a folder or file that you need to ignore, you can create a file with name “.gitignore” and add path to file/folder in it, git will ignore files/folders listed in it.