#!/bin/sh
#
# /space/gentoo/cvsroot/gentoo-x86/sys-apps/cronbase/files/run-crons,v 1.3 2002/05/13 18:34:05 bangert Exp
#
# 20 Apr 2002; Thilo Bangert <bangert@gentoo.org> run-crons:
#
# moved lastrun directory to /var/spool/cron/lastrun
#
#
# 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/spool/cron/lastrun

mkdir -p /var/spool/cron/lastrun

#

for CRONDIR in /etc/cron.{hourly,daily,weekly,monthly}
do
   
    test -d $CRONDIR || continue
    BASE=${CRONDIR##*/}
    test -e /var/spool/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/spool/cron/lastrun/$BASE $TIME | \
	    xargs --no-run-if-empty rm 
    }
    if test ! -e /var/spool/cron/lastrun/$BASE ; then
	touch /var/spool/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/spool/cron/lastrun
find /var/spool/cron/lastrun -newer /var/spool/cron/lastrun | \
    xargs --no-run-if-empty rm

