Simple change detector for cpanel template files

Print Friendly

OK, in answer to requests, here is a simple bash script to check any file for changes. It could have been done with MD5 hashes, but it’s probably not necessary (overkill).

Just copy the file you want to check and rename it with a different extension (e.g. .check)

Then just run the following script under a crontab entry – probably best a short while after upcp is run.

#!/bin/bash
COMPARE="`diff --brief /usr/local/cpanel/etc/httptemplates/apache2_2/default /usr/local/cpanel/etc/httptemplates/apache2_2/default.check`"
if [ ${#COMPARE} -gt 0 ]; then
   echo "There was a change found in /usr/local/cpanel/etc/httptemplates/apache2_2/default" | /bin/mail -s "Changes in Cpanel Templates Detected `date`" santfiles@mac.com
fi

If the files are the same then diff should return nothing, so we just check for a return value that is greater than 0.

Of course, if you happen to have CSF and LFD installed, then there is no need for any of this – just set up a File watch. (making sure you set LF_DIRWATCH_FILE to a value other than zero to make sure your watched files and directories are actually being watched!)

As always – test test, and test again before using anything here in a production environment!

Tags: , ,

No comments yet.

Leave a Reply

Bot test *