#!/bin/sh -
usage () {
echo "usage: $0 <directory of files to execute>" 1>&2
echo "or $0 { daily | weekly | monthly }" 1>&2
exit 1
}
if [ $ usage
fi
if [ -r /etc/defaults/periodic.conf ]; then
. /etc/defaults/periodic.conf
source_periodic_confs
fi
host=`hostname`
export host
tmp_output=`mktemp ${TMPDIR:-/tmp}/periodic.XXXXXXXXXX`
for arg
do
eval output=\$${arg case "$output" in
/*) pipe="cat >>$output";;
"") pipe=cat;;
*) pipe="mail -E -s '$host ${arg##*/} run output' $output";;
esac
success=YES info=YES badconfig=NO empty_output=YES for var in success info badconfig empty_output
do
case $(eval echo "\$${arg##*/}_show_$var") in
[Yy][Ee][Ss]) eval $var=YES;;
[Nn][Oo]) eval $var=NO;;
esac
done
case $arg in
/*) if [ -d "$arg" ]
then
dirlist="$arg"
else
echo "$0: $arg not found" >&2
continue
fi;;
*) dirlist=
for top in /etc/periodic ${local_periodic}
do
[ -d $top/$arg ] && dirlist="$dirlist $top/$arg"
done;;
esac
{
echo
date
empty=TRUE
processed=0
for dir in $dirlist
do
for file in $dir/*
do
if [ -x $file -a ! -d $file ]
then
output=TRUE
processed=$(($processed + 1))
$file </dev/null >$tmp_output 2>&1
rc=$?
if [ -s $tmp_output ]
then
case $rc in
0) [ $success = NO ] && output=FALSE;;
1) [ $info = NO ] && output=FALSE;;
2) [ $badconfig = NO ] && output=FALSE;;
esac
[ $output = TRUE ] && { cat $tmp_output; empty=FALSE; }
fi
cp /dev/null $tmp_output
fi
done
done
if [ $empty = TRUE ]
then
if [ $empty_output = TRUE ]
then
[ $processed = 1 ] && plural= || plural=s
echo "No output from the $processed file$plural processed"
fi
else
echo ""
echo "-- End of $arg output --"
fi
} | eval $pipe
done
rm -f $tmp_output