roger-skyline-1/files/check_crontab.sh
2018-12-13 18:51:03 +01:00

28 lines
698 B
Bash
Executable File

#!/bin/bash
cron=/etc/crontab
md5old=/etc/crontab_save
log=/var/log/check_crontab.log
printf "##### %s #####\n" "$(date)" >>$log
if [ ! -f $md5old ]
then
printf "Error: %s don't exist\nCreating %s ...\n" "$md5old" "$md5old" >>$log
md5sum $cron >$md5old
exit 1
fi
if [ ! -s $md5old ]
then
printf "Error: %s is empty\nadding md5 hash to %s ...\n" "$md5old" "$md5old" >>$log
md5sum $cron >$md5old
exit 1
fi
if [ ! $(md5sum -c $md5old 2>/dev/null | grep $cron | cut -d' ' -f2) = "OK" ]
then
printf "Error: %s modified\nsending mail ...\n" >>$log
echo "crontab has changed T_T" | mail -s "!!! PANIC !!! PANIC !!!! PANIC !!!" root
else
printf "file OK\n" >>$log
fi