Detect changes to crontab

Dear All,

My server is running crontabs of 4 different users.
I want to develop a script that whenever a particular change occurs in a crontab , it is detected and the particular change is noted into a file.

Kindly let me know of suggestions on how it can be achieved.

My algo would be:

  1. Make a copy of the file
  2. Compare present crontab to copy.
  3. Use diff to comapre both files.
  4. If change present subtract new file from old one and extract the difference.

Regards

---------- Post updated at 12:05 PM ---------- Previous update was at 10:01 AM ----------

DIFF=`comm -13 /var/spool/cron/crontabs/jun /var/tmp/temp_crontabs/jun_temp`
#DIFF=`comm -13 /var/tmp/temp_crontabs/jun_temp /var/spool/cron/crontabs/jun`

if [ "$DIFF" == "" ]
then

echo "======================"
echo "No change in crontab"
echo "======================"

else

echo "$DIFF"
echo "$DIFF"|mailx -s "Crontab Change Alert" my-email@id.com
fi


cp /var/spool/cron/crontabs/jun /var/tmp/temp_crontabs/jun_temp

This is what Ive done till now but its not giving me the proper result.

I just use a text file instead of a real crontab file to test

bash-3.2$ cat c1
* * * * * cmd 1
* * * * * cmd 2
* * * * * cmd 3
bash-3.2$ cat c2
* * * * * cmd 4
* * * * * cmd 5
* * * * * cmd 6
* * * * * cmd 1
bash-3.2$ 
bash-3.2$ bash c.sh
* * * * * cmd 4
* * * * * cmd 5
* * * * * cmd 6
bash-3.2$ 
bash-3.2$ 
bash-3.2$ cat c.sh
#!/bin/bash
DIFF=$(comm <(sort c1) <(sort c2) | awk -F "\t" 'length($2)>0{print $2}' )
if [ "${DIFF}" != "" ]
then
        IFS=$"\n";
        echo ${DIFF}
fi