[oracle@nposqa1 ~]$ cat /home/oracle/DBA/bin/crontab_compare.bash
#!/bin/bash
# set -x
# Get the current crontab entries
# Compare with the expected crontab entries
# Notify if any changes found
#########################################################################################
# Control file locations separately.
# create following variables in the file
# ORIGFILE = Original file to compare the current crontab entries
# EMAILRECIPIENTS='example@example.com'
# EMAILBODY=Location of email body file.
VARIABLES=$1
. $VARIABLES
HOST=$(hostname)
CURRFILE='/tmp/currcron.file'
DIFFILE='/tmp/crondif.file'
crontab -l > $CURRFILE
diff $ORIGFILE $CURRFILE > $DIFFILE
#Function to push email to users on alert
function pushmail
{
SUBJ=$1
MAILBODY=$2
RECIPIENTS=$3
mail -s "$SUBJ" $RECIPIENTS < $MAILBODY
}
if [ -s $DIFFILE ]
then
echo "" > $EMAILBODY
echo "Attention: Found changes in the current crontab entry" >>$EMAILBODY
echo "" >> $EMAILBODY
echo "---- Below are the changes from DIFF command ----" >> $EMAILBODY
echo "" >> $EMAILBODY
cat $DIFFILE >> $EMAILBODY
pushmail "ALERT: Found changes in crontab entry on server $HOST" $EMAILBODY $EMAILRECIPIENTS
fi