4 # Run nightly periodic scripts
6 # usage: periodic { daily | weekly | monthly | security } - run standard scripts
7 # periodic /absolute/path/to/directory - run periodic scripts in dir
11 echo "usage: $0 <directory of files to execute>" 1>&2
12 echo "or $0 { daily | weekly | monthly | security }" 1>&2
18 # Where's our output going ?
19 eval output=\$${1##*/}_output
21 /*) pipe="cat >>$output";;
23 *) pipe="mail -E -s '$host ${2}${2:+ }${1##*/} run output' $output";;
28 if [ $# -lt 1 ] ; then
32 _localbase=`/sbin/sysctl -n user.localbase 2> /dev/null`
33 # Set default value of _localbase if not previously set
34 : ${_localbase:="/usr/local"}
36 # Use a deterministic path to match the preset from /etc/crontab in case
37 # periodic is run interactively.
38 export PATH=/sbin:/bin:/usr/sbin:/usr/bin:${_localbase}/sbin:${_localbase}/bin
40 # If possible, check the global system configuration file,
41 # to see if there are additional dirs to check
42 if [ -r /etc/defaults/periodic.conf ]; then
43 . /etc/defaults/periodic.conf
50 # If we were called normally, then create a lock file for each argument
51 # in turn and reinvoke ourselves with the LOCKED argument. This prevents
52 # very long running jobs from being overlapped by another run as this is
53 # will lead the system running progressively slower and more and more jobs
55 if [ $1 != "LOCKED" ]; then
58 lockfile=/var/run/periodic.${arg##*/}.lock
59 lockf -s -t 0 "${lockfile}" /bin/sh $0 LOCKED "$arg"
63 echo "can't create ${lockfile}" | \
64 output_pipe $arg "$PERIODIC"
68 echo "$host ${arg##*/} prior run still in progress" | \
69 output_pipe $arg "$PERIODIC"
86 if [ -z "$PERIODIC_ANTICONGESTION_FILE" ] ; then
87 export PERIODIC_ANTICONGESTION_FILE=`mktemp ${TMPDIR:-/tmp}/periodic.anticongestion.XXXXXXXXXX`
88 remove_periodic_anticongestion_file=yes
90 # We might be in a recursive invocation; let the top-level invocation
92 remove_periodic_anticongestion_file=no
95 export PERIODIC_IS_INTERACTIVE=1
97 tmp_output=`mktemp ${TMPDIR:-/tmp}/periodic.XXXXXXXXXX`
99 export PERIODIC="$arg${PERIODIC:+ }${PERIODIC}"
101 # Execute each executable file in the directory list. If the x bit is not
102 # set, assume the user didn't really want us to muck with it (it's a
103 # README file or has been disabled).
105 success=YES info=YES badconfig=NO empty_output=YES # Defaults when ${run}_* aren't YES/NO
106 for var in success info badconfig empty_output; do
107 case $(eval echo "\$${arg##*/}_show_$var") in
108 [Yy][Ee][Ss]) eval $var=YES;;
109 [Nn][Oo]) eval $var=NO;;
114 /*) if [ -d "$arg" ]; then
117 echo "$0: $arg not found" >&2
122 for top in /etc/periodic ${local_periodic}; do
123 [ -d $top/$arg ] && dirlist="$dirlist $top/$arg"
131 for dir in $dirlist; do
132 for file in $dir/*; do
133 if [ -x $file -a ! -d $file ]; then
135 processed=$(($processed + 1))
136 $file </dev/null >$tmp_output 2>&1
138 if [ -s $tmp_output ]; then
140 0) [ $success = NO ] && output=FALSE;;
141 1) [ $info = NO ] && output=FALSE;;
142 2) [ $badconfig = NO ] && output=FALSE;;
144 [ $output = TRUE ] && { cat $tmp_output; empty=FALSE; }
146 cp /dev/null $tmp_output
150 if [ $empty = TRUE ]; then
151 if [ $empty_output = TRUE ]; then
152 [ $processed = 1 ] && plural= || plural=s
153 echo "No output from the $processed file$plural processed"
157 echo "-- End of $arg output --"
159 } | output_pipe $arg "$context"
162 if [ $remove_periodic_anticongestion_file = "yes" ] ; then
163 rm -f $PERIODIC_ANTICONGESTION_FILE