#!/bin/sh
#
#
# Author: Achim Gottinger <achim@gentoo.org>
#
# Mostly copied from SuSE
#
# this script looks into /etc/cron.[hourly|daily|weekly|monthly]
# for scripts to be executed. The info about last run is stored in 
# /var/cron/lastrun

mkdir -p /var/cron/lastrun

#

for CRONDIR in /etc/cron.{hourly,daily,weekly,monthly}
do
   
    test -d $CRONDIR || continue
    BASE=${CRONDIR##*/}
    test -e /var/cron/lastrun/$BASE && {

	case $BASE in
	    cron.hourly)  TIME="-cmin  +60 -or -cmin  60" ;;
	    cron.daily)   TIME="-ctime +1  -or -ctime 1"  ;;
	    cron.weekly)  TIME="-ctime +7  -or -ctime 7"  ;;
	    cron.monthly) TIME="-ctime +30 -or -ctime 30" ;;
	esac
	eval find /var/cron/lastrun/$BASE $TIME | \
	    xargs --no-run-if-empty rm 
    }
    if test ! -e /var/cron/lastrun/$BASE ; then
	touch /var/cron/lastrun/$BASE

	set +e
	for SCRIPT in $CRONDIR/*
	do
	    test -d $SCRIPT && continue
	    if test -x $SCRIPT ; then
		$SCRIPT
	    fi
	done
    fi
done

#

touch /var/cron/lastrun
find /var/cron/lastrun -newer /var/cron/lastrun | \
    xargs --no-run-if-empty rm

