diff -dupr fcron-3.0.4.orig/script/check_system_crontabs fcron-3.0.4/script/check_system_crontabs --- fcron-3.0.4.orig/script/check_system_crontabs 2009-09-02 12:02:54.032305325 +0200 +++ fcron-3.0.4/script/check_system_crontabs 2009-09-02 15:33:38.742306163 +0200 @@ -85,13 +85,12 @@ FCRONTAB_FILE_TMP= cleanup() { # remove temporary file (if any) - [ -e "$FCRONTAB_FILE_TMP" ] && rm -f $FCRONTAB_FILE_TMP + [ -e "$FCRONTAB_FILE_TMP" ] && rm -f "$FCRONTAB_FILE_TMP" } trap "eval cleanup" INT TERM HUP -if [ -x "`type -p mktemp`" ]; then - FCRONTAB_FILE_TMP=`mktemp /tmp/fcrontab.XXXXXX` -else +FCRONTAB_FILE_TMP="`mktemp /tmp/fcrontab.XXXXXX 2>/dev/null`" +if [ $? -ne 0 ]; then FCRONTAB_FILE_TMP=/tmp/fcrontab.$$ fi @@ -136,7 +135,7 @@ VERBOSE= FORCE= # read command line arguments -while [ "$#" -gt 0 ]; do +while [ $# -gt 0 ]; do case "$1" in -v) VERBOSE=true @@ -186,8 +185,9 @@ if [ -n "$FCRONTAB_PROG" ]; then [ -d "$FCRONTAB_PROG" ] && FCRONTAB_PROG="$FCRONTAB_PROG/fcrontab" [ ! -x "$FCRONTAB_PROG" ] && die "Invalid fcrontab executable or path specified with -p!" else - if [ -x "`type -p fcrontab`" ]; then - FCRONTAB_PROG="`type -p fcrontab`" + fcrontab -V 2>/dev/null + if [ $? -eq 0 ]; then + FCRONTAB_PROG=fcrontab elif [ -x /usr/bin/fcrontab ]; then FCRONTAB_PROG=/usr/bin/fcrontab elif [ -x /usr/local/bin/fcrontab ]; then @@ -202,58 +202,67 @@ if [ -z "$CROND_DIR" -o -z "$CRONTAB_FIL die "Must specify all system crontab files." fi -# Function to scan for valid files in $CROND_DIR -crond_files() -{ - [ ! -d $CROND_DIR ] && return - local FILES=`echo $CROND_DIR/*` - local FILE - [ "$FILES" = "$CROND_DIR/*" ] && return - for FILE in $FILES; do - if [ ! -d $FILE -a $FILE = "${FILE%\~}" ]; then - echo $FILE - fi - done -} - - # Function to build up a system crontab and tell fcron it's changed rebuild_and_notify() { logger -i -p cron.notice -t "check_system_crontabs" "Rebuilding the system fcrontab..." # put a warning message at the top of the file - echo -e "########################################" > $FCRONTAB_FILE_TMP - 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 "# those files is changed.\n#\n\n" >> $FCRONTAB_FILE_TMP + cat <<_EOF_ > "$FCRONTAB_FILE_TMP" +######################################## +# WARNING!!! DO NOT EDIT THIS FILE!!! # +######################################## +# Do not edit this file! It is automatically generated from +# the $CRONTAB_FILE, the $FCRONTAB_FILE and $CROND_DIR/* files whenever one of +# those files is changed. +# + +_EOF_ # 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 - cat $CRONTAB_FILE >> $FCRONTAB_FILE_TMP + if [ -f "$CRONTAB_FILE" -a ! -L "$CRONTAB_FILE" ]; then + cat - "$CRONTAB_FILE" <<_EOF_ >> "$FCRONTAB_FILE_TMP" + + +######################################## +# $CRONTAB_FILE +######################################## + +_EOF_ fi # print a nice filename header for each file in /etc/cron.d/ # and include its contents into the new fcron system crontab - for i in `crond_files` ; do - echo -e "\n\n########################################\n# $i\n########################################\n" >> $FCRONTAB_FILE_TMP - cat $i >> $FCRONTAB_FILE_TMP + for i in "$CROND_DIR"/* ; do + if [ -r "$i" -a ! -d "$i" -a "$i" = "${i%\~}" ]; then + cat - "$i" <<_EOF_ >> "$FCRONTAB_FILE_TMP" + + +######################################## +# $i +######################################## + +_EOF_ + fi 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 + if [ -f "$FCRONTAB_FILE" -a ! -L "$FCRONTAB_FILE" ]; then + cat - "$FCRONTAB_FILE" <<_EOF_ >> "$FCRONTAB_FILE_TMP" + + +######################################## +# $FCRONTAB_FILE +######################################## + +_EOF_ 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 + 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 -c $FCRON_CONFIG_FILE $FCRONTAB_FILE_TMP -u systab + "$FCRONTAB_PROG" -c "$FCRON_CONFIG_FILE" "$FCRONTAB_FILE_TMP" -u systab } NEED_REBUILD=0 @@ -274,11 +283,11 @@ if [ -n "$FORCE" ]; then else - if [ -d $CROND_DIR ]; then + 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 + if [ -n "$(find "$CROND_DIR" -prune -type d -newer "$FCRONTABS_DIR"/systab.orig 2>/dev/null)" ]; then info "Changes detected in $CROND_DIR" NEED_REBUILD=1 @@ -286,31 +295,22 @@ else 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 + if [ -n "$(find "$CROND_DIR"/* -prune -type f ! -name '*~' -newer "$FCRONTABS_DIR"/systab.orig 2>/dev/null)" ]; then - info "Changes detected in $CROND_DIR" - NEED_REBUILD=1 + info "Changes detected in $CROND_DIR" + NEED_REBUILD=1 - fi - done + fi fi fi - # 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 - - info "Changes detected in $CRONTAB_FILE" - NEED_REBUILD=1 - - 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 + # Test the standard /etc/crontab and /etc/fcrontab files and see if they have changed + REBUILD_TMPSTR="$(find "$CRONTAB_FILE" "$FCRONTAB_FILE" -prune -type f -newer "$FCRONTABS_DIR"/systab.orig -exec echo "Changes detected in {}" ';' 2>/dev/null)" + if [ -n "${REBUILD_TMPSTR}" ]; then - info "Changes detected in $FCRONTAB_FILE" + info "${REBUILD_TMPSTR}" NEED_REBUILD=1 fi