Operating System - Linux
1829516 Members
1304 Online
109991 Solutions
New Discussion

Crontab Modification Script

 
SOLVED
Go to solution
Kyle D. Harris
Regular Advisor

Crontab Modification Script

#This script is to identify if the crontab has been modified and then emails the sys admin of the changes. For some reason i can't get the files created or an email sent when i test it out. I have it to run in the crontab every minute. Can somebody give me ideas?? Thanks! Semper Fi!

crontab -l > /usr/local/apache/htdocs/harris/crontabtext
diff /usr/local/apache/htdocs/harris/crontabtext /usr/local/apache/htdocs/harris/crontabtext.backup > /tmp/crontab_changes
if [ -s /tmp/crontab_changes ] #send mail if file is not empty
then
echo "The Crontab has been changed" | sendmail harriskd@matcom.usmc.mil
cp /usr/local/apache/htdocs/harris/crontabtext /usr/local/apache/htdocs/harris/crontabtext.backup
rm /tmp/crontab_changes
fi
4 REPLIES 4
Jerome Henry
Honored Contributor
Solution

Re: Crontab Modification Script

A script should start with :
#!bin/bash
#
in order to let your system know it has to work with shell scripting.
Try adding a line after fi :
what if nothing changes ?
I suggest 'touch test.txt' to debug,
then 'exit 0' for final version.

hth

J
You can lean only on what resists you...
Kyle D. Harris
Regular Advisor

Re: Crontab Modification Script

Jerome-
Thanks. That seemed to help. I finally got this script to at least run and the files got created when i would change the crontab. The only thing left not working is it sending email to me via sendmail. Is my sendmail line correct? It looks right to me. Thanks for your help. Pts have been rewarded!

Kyle
Claudio Cilloni
Honored Contributor

Re: Crontab Modification Script

I think you should use the 'mail' command, not 'sendmail'. Just this substitution is enough.

hth
Claudio
Jerome Henry
Honored Contributor

Re: Crontab Modification Script

Hi Kyle,

tks fr your points !

RE sendmail issue, your line is correct, except that message should follow endmail command :
try /usr/sbin/sendmail harriskd@matcom.usmc.mil <"The Crontab has been changed"
It should work.
Claudio suggestion would also work, as mail command works very well in the pipe option.
Glad your script works !

J
You can lean only on what resists you...