3 # $FreeBSD: src/usr.sbin/periodic/periodic.sh,v 1.9.2.8 2002/05/21 03:09:35 brian Exp $
4 # $DragonFly: src/usr.sbin/periodic/periodic.sh,v 1.2 2003/06/17 04:29:59 dillon Exp $
6 # Run nightly periodic scripts
8 # usage: periodic { daily | weekly | monthly } - run standard periodic scripts
9 # periodic /absolute/path/to/directory - run periodic scripts in dir
13 echo "usage: $0 <directory of files to execute>" 1>&2
14 echo "or $0 { daily | weekly | monthly }" 1>&2
18 if [ $# -lt 1 ] ; then
22 # If possible, check the global system configuration file,
23 # to see if there are additional dirs to check
24 if [ -r /etc/defaults/periodic.conf ]; then
25 . /etc/defaults/periodic.conf
31 tmp_output=`mktemp ${TMPDIR:-/tmp}/periodic.XXXXXXXXXX`
33 # Execute each executable file in the directory list. If the x bit is not
34 # set, assume the user didn't really want us to muck with it (it's a
35 # README file or has been disabled).
39 # Where's our output going ?
40 eval output=\$${arg##*/}_output
42 /*) pipe="cat >>$output"
48 *) pipe="mail -s '$host ${arg##*/} run output' $output"
53 success=YES info=YES badconfig=NO # Defaults when ${run}_* aren't YES/NO
54 for var in success info badconfig verbose
56 case $(eval echo "\$${arg##*/}_show_$var") in
57 [Yy][Ee][Ss]) eval $var=YES;;
58 [Nn][Oo]) eval $var=NO;;
67 echo "$0: $arg not found" >&2
71 for top in /etc/periodic ${local_periodic}
73 [ -d $top/$arg ] && dirlist="$dirlist $top/$arg"
80 if [ "$verbose" = YES ]
82 echo "-- Start of $arg output -- `date`"
88 if [ -x $file -a ! -d $file ]
91 if [ "$verbose" = YES ]
93 echo "-- Start of $arg $file output -- `date`"
95 processed=$(($processed + 1))
96 $file </dev/null >$tmp_output 2>&1
101 0) [ $success = NO ] && output=FALSE;;
102 1) [ $info = NO ] && output=FALSE;;
103 2) [ $badconfig = NO ] && output=FALSE;;
105 [ $output = TRUE ] && { cat $tmp_output; empty=FALSE; }
107 cp /dev/null $tmp_output
113 [ $processed = 1 ] && plural= || plural=s
114 echo "No output from the $processed file$plural processed"
116 if [ "$verbose" = YES ]
119 echo "-- End of $arg output -- `date`"