Description: Allow multiple system crontab directories (default /etc/cron.d and /usr/local/etc/cron.d). Allow to change systab user via option DEFAULT_SYSTAB_USER. Move content of the file /etc/fcrontab to the top of the system fcrontab file (that allow us to set some default options for all other files). Sergei Butakov --- fcron-3.0.4/script/check_system_crontabs.orig 2008-10-21 20:20:11.490586114 +0600 +++ fcron-3.0.6/script/check_system_crontabs.bash 2010-10-26 02:30 @@ -4,10 +4,11 @@ # # Script to check and see if any system (f)crontabs have changed, and if so # build a fcrontab file from /etc/crontab, /etc/fcrontab and files from -# /etc/cron.d/ and notify fcron about the change. +# /etc/cron.d/, /usr/local/etc/cron.d/ and notify fcron about the change. # # WARNING : - if you run this script, your system fcrontab will be overridden -# by the content of /etc/crontab, /etc/fcrontab, /etc/cron.d : +# by the content of /etc/crontab, /etc/fcrontab, /etc/cron.d/, +# /usr/local/etc/cron.d/ : # save the content of your system fcrontab first if necessary. # # - you should not have the same lines in /etc/crontab @@ -65,19 +66,30 @@ # + bug fixes and enhancement. # 2005/04/27 Daniel Himler Security enhancements and cleanups. # 2005/09/14 Damon Harper Command lines options, cleanups. +# 2008/10/21 Sergei Butakov Allow multiple system crontab directories +# sergei@bslos.com and set DEFAULT_CROND_DIR to +# "/etc/cron.d /usr/local/etc/cron.d" +# Allow to change systab user via option +# DEFAULT_SYSTAB_USER +# Move content of the file /etc/fcrontab +# to the top of the system fcrontab file +# (that allow us to set some default options +# for all other files) # ############################## # DEFAULT CONFIGURATION DEFAULT_SLEEP_TIME_BEFORE_REBUILD=30 -DEFAULT_CROND_DIR=/etc/cron.d +DEFAULT_CROND_DIR="/etc/cron.d /usr/local/etc/cron.d" DEFAULT_CRONTAB_FILE=/etc/crontab DEFAULT_FCRONTAB_FILE=/etc/fcrontab FCRONTAB_PROG=/usr/bin/fcrontab FCRONTABS_DIR=/var/spool/fcron +DEFAULT_SYSTAB_USER=systab + # END OF DEFAULT CONFIGURATION ############################## @@ -119,7 +131,7 @@ only if it cannot be found automatically. -F FILE System fcrontab file (default $DEFAULT_FCRONTAB_FILE). -C FILE System crontab file (default $DEFAULT_CRONTAB_FILE). - -D DIR System crontab directory (default $DEFAULT_CROND_DIR). + -D DIR System crontab directories (default $DEFAULT_CROND_DIR). -h This help text. _EOF_ exit @@ -197,18 +209,25 @@ fi # Function to scan for valid files in $CROND_DIR -crond_files() +crond_files_from_dir() { - [ ! -d $CROND_DIR ] && return - local FILES=`echo $CROND_DIR/*` + DIR="$1" + [ ! -d $DIR ] && return + local FILES=`echo $DIR/*` local FILE - [ "$FILES" = "$CROND_DIR/*" ] && return + [ "$FILES" = "$DIR/*" ] && return for FILE in $FILES; do if [ ! -d $FILE -a $FILE = "${FILE%\~}" ]; then echo $FILE fi done } +crond_files() +{ + for DIR in $CROND_DIR; do + crond_files_from_dir "$DIR" + done +} # Function to build up a system crontab and tell fcron it's changed @@ -221,9 +240,15 @@ echo -e "# WARNING!!! DO NOT EDIT THIS FILE!!! #" >> $FCRONTAB_FILE_TMP echo -e "########################################" >> $FCRONTAB_FILE_TMP echo -e "# Do not edit this file! It is automatically generated from" >> $FCRONTAB_FILE_TMP - echo -e "# the $CRONTAB_FILE, the $FCRONTAB_FILE and $CROND_DIR/* files whenever one of" >> $FCRONTAB_FILE_TMP + echo -e "# the $CRONTAB_FILE, the $FCRONTAB_FILE and $CROND_DIR files whenever one of" >> $FCRONTAB_FILE_TMP echo -e "# those files is changed.\n#\n\n" >> $FCRONTAB_FILE_TMP + # include the system fcrontab file if it exists and is not a symbolic link + if [ -f $FCRONTAB_FILE -a ! -L $FCRONTAB_FILE ]; then + echo -e "\n\n########################################\n# $FCRONTAB_FILE\n########################################\n" >> $FCRONTAB_FILE_TMP + cat $FCRONTAB_FILE >> $FCRONTAB_FILE_TMP + fi + # include the standard system crontab file if it exists and is not a symbolic link if [ -f $CRONTAB_FILE -a ! -L $CRONTAB_FILE ]; then echo -e "\n\n########################################\n# $CRONTAB_FILE\n########################################\n" >> $FCRONTAB_FILE_TMP @@ -237,17 +262,11 @@ cat $i >> $FCRONTAB_FILE_TMP done - # include the system fcrontab file if it exists and is not a symbolic link - if [ -f $FCRONTAB_FILE -a ! -L $FCRONTAB_FILE ]; then - echo -e "\n\n########################################\n# $FCRONTAB_FILE\n########################################\n" >> $FCRONTAB_FILE_TMP - cat $FCRONTAB_FILE >> $FCRONTAB_FILE_TMP - fi - # Replace "@hourly" style Vixie cron extensions which fcron doesn't parse sed -i -e "s/@yearly/0 0 1 1 */g" -e "s/@annually/0 0 1 1 */g" -e "s/@monthly/0 0 1 * */g" -e "s/@weekly/0 0 * * 0/g" -e "s/@daily/0 0 * * */g" -e "s/@midnight/0 0 * * */g" -e "s/@hourly/0 * * * */g" $FCRONTAB_FILE_TMP # notify fcron about the updated file - $FCRONTAB_PROG $FCRONTAB_FILE_TMP -u systab + $FCRONTAB_PROG $FCRONTAB_FILE_TMP -u $DEFAULT_SYSTAB_USER } NEED_REBUILD=0 @@ -268,33 +287,31 @@ else - if [ -d $CROND_DIR ]; then - - # This test works for file creation/deletion (deletion is not detected - # by the next test) - if [ $CROND_DIR -nt $FCRONTABS_DIR/systab.orig ]; then - - info "Changes detected in $CROND_DIR" - NEED_REBUILD=1 - - else - - # Test each one and see if it's newer than our timestamp file - for i in `crond_files` ; do - if [ $i -nt $FCRONTABS_DIR/systab.orig ]; then + # This test works for file creation/deletion (deletion is not detected + # by the next test) + for DIR in $CROND_DIR; do + if [ -d $DIR ]; then + if [ $DIR -nt $FCRONTABS_DIR/$DEFAULT_SYSTAB_USER.orig ]; then + + info "Changes detected in $DIR" + NEED_REBUILD=1 + + fi + fi + done - info "Changes detected in $CROND_DIR" - NEED_REBUILD=1 + # Test each file in $CROND_DIR and see if it's newer than our timestamp file + for i in `crond_files` ; do + if [ $i -nt $FCRONTABS_DIR/$DEFAULT_SYSTAB_USER.orig ]; then - fi - done + info "Changes detected in $i" + NEED_REBUILD=1 fi - - fi + done # Test the standard /etc/crontab file and see if it has changed - if [ -f $CRONTAB_FILE -a $CRONTAB_FILE -nt $FCRONTABS_DIR/systab.orig ]; then + if [ -f $CRONTAB_FILE -a $CRONTAB_FILE -nt $FCRONTABS_DIR/$DEFAULT_SYSTAB_USER.orig ]; then info "Changes detected in $CRONTAB_FILE" NEED_REBUILD=1 @@ -302,7 +319,7 @@ fi # Test the standard /etc/fcrontab file and see if it has changed - if [ -f $FCRONTAB_FILE -a $FCRONTAB_FILE -nt $FCRONTABS_DIR/systab.orig ]; then + if [ -f $FCRONTAB_FILE -a $FCRONTAB_FILE -nt $FCRONTABS_DIR/$DEFAULT_SYSTAB_USER.orig ]; then info "Changes detected in $FCRONTAB_FILE" NEED_REBUILD=1