LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - General (https://www.linuxquestions.org/questions/linux-general-1/)
-   -   Script to compare crontabs (https://www.linuxquestions.org/questions/linux-general-1/script-to-compare-crontabs-4175512119/)

manup 07-24-2014 03:56 AM

Script to compare crontabs
 
Hi I Need a script to monitor the cron entries and if there is any change in the crontab entry it needs to alert me.
For this I have used the method by taking a copy of current crontab then it needs to compare the crontabs every day.If there is any alteration found it needs to alert me.Is this possible?

I first Copied my current crontab using "crontab -l>cron.txt"
then by "crontab -l > $(date +%Y%m%d).crontab" took a copy by date and day wise but I dont know how to compare this files in aregular manner and send mails if it found alteration..

TenTenths 07-24-2014 04:02 AM

Ok, so what have you written so far?

manup 07-24-2014 04:27 AM

Quote:

Originally Posted by TenTenths (Post 5208796)
Ok, so what have you written so far?

CRDI=/var/spool/cron/crontabs
CHECKF=/tmp/last.crontab.check
ALERT=iam@userhost
if [ -f $CHECKF ]
then
find $CRDI -type f -newer $CHECKF | while read tabfile
do
echo "Crontab file for user $(basename $tabfile) has changed" | mail -s "Crontab changed" $ALERT
done
fi
touch $CHECKF

will this script fit for my above requirement?

Hangdog42 07-27-2014 08:41 AM

Why don't you just compare the md5 values of the crontab vs a standard? If they don't match, you send an email. You could store all the standard md5 values in a restricted access file. Seems a bit safer to me than relying on system dates.


All times are GMT -5. The time now is 12:54 PM.