LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 07-24-2014, 03:56 AM   #1
manup
LQ Newbie
 
Registered: Jul 2014
Posts: 2

Rep: Reputation: Disabled
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..

Last edited by manup; 07-24-2014 at 04:12 AM.
 
Old 07-24-2014, 04:02 AM   #2
TenTenths
Senior Member
 
Registered: Aug 2011
Location: Dublin
Distribution: Centos 5 / 6 / 7
Posts: 3,461

Rep: Reputation: 1552Reputation: 1552Reputation: 1552Reputation: 1552Reputation: 1552Reputation: 1552Reputation: 1552Reputation: 1552Reputation: 1552Reputation: 1552Reputation: 1552
Ok, so what have you written so far?
 
Old 07-24-2014, 04:27 AM   #3
manup
LQ Newbie
 
Registered: Jul 2014
Posts: 2

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by TenTenths View Post
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?
 
Old 07-27-2014, 08:41 AM   #4
Hangdog42
LQ Veteran
 
Registered: Feb 2003
Location: Maryland
Distribution: Slackware
Posts: 7,803
Blog Entries: 1

Rep: Reputation: 422Reputation: 422Reputation: 422Reputation: 422Reputation: 422
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.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] Compare 2 files with script. elalexluna83 Programming 4 09-25-2012 06:50 PM
[SOLVED] md5sum compare script chris_carr Linux - Newbie 19 11-07-2011 01:21 PM
compare size script trintukaz Programming 36 09-24-2011 07:58 AM
Please help on making a compare script Magil Programming 7 12-14-2009 05:13 AM
Help with a Directory Compare Script bullfrog Linux - General 1 02-04-2003 08:05 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

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

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration