1997-08-12 17:48:49 +00:00
|
|
|
#!/bin/sh -
|
|
|
|
#
|
1999-08-28 01:35:59 +00:00
|
|
|
# $FreeBSD$
|
1997-08-12 17:48:49 +00:00
|
|
|
#
|
|
|
|
# Run nightly periodic scripts
|
|
|
|
#
|
|
|
|
# usage: periodic { daily | weekly | monthly } - run standard periodic scripts
|
|
|
|
# periodic /absolute/path/to/directory - run periodic scripts in dir
|
|
|
|
#
|
|
|
|
|
1997-08-13 06:02:18 +00:00
|
|
|
usage () {
|
1997-08-12 17:48:49 +00:00
|
|
|
echo "usage: $0 <directory of files to execute>" 1>&2
|
1997-08-13 06:02:18 +00:00
|
|
|
echo "or $0 { daily | weekly | monthly }" 1>&2
|
1997-08-12 17:48:49 +00:00
|
|
|
exit 1
|
1997-08-13 06:02:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if [ $# -lt 1 ] ; then
|
|
|
|
usage
|
|
|
|
fi
|
|
|
|
|
1999-02-14 20:06:02 +00:00
|
|
|
# If possible, check the global system configuration file,
|
|
|
|
# to see if there are additional dirs to check
|
2000-06-23 01:18:31 +00:00
|
|
|
if [ -r /etc/defaults/periodic.conf ]; then
|
|
|
|
. /etc/defaults/periodic.conf
|
|
|
|
source_periodic_confs
|
1997-08-12 17:48:49 +00:00
|
|
|
fi
|
|
|
|
|
2000-09-14 17:19:15 +00:00
|
|
|
dirlist=
|
1997-08-12 17:48:49 +00:00
|
|
|
|
1997-08-13 06:02:18 +00:00
|
|
|
# If a full path was not specified, check the standard cron areas
|
1997-08-12 17:48:49 +00:00
|
|
|
|
2000-09-14 17:19:15 +00:00
|
|
|
for dir
|
|
|
|
do
|
|
|
|
case "$dir" in
|
|
|
|
/*)
|
|
|
|
if [ -d "$dir" ]
|
|
|
|
then
|
|
|
|
dirlist="$dirlist $dir"
|
|
|
|
else
|
|
|
|
echo "$0: $dir not found" >&2
|
|
|
|
fi;;
|
|
|
|
*)
|
|
|
|
for top in /etc/periodic ${local_periodic}
|
|
|
|
do
|
|
|
|
[ -d $top/$dir ] && dirlist="$dirlist $top/$dir"
|
|
|
|
done;;
|
|
|
|
esac
|
|
|
|
done
|
1997-08-12 17:48:49 +00:00
|
|
|
|
1999-01-01 17:37:33 +00:00
|
|
|
host=`hostname`
|
2000-03-29 07:05:29 +00:00
|
|
|
export host
|
2000-09-14 17:19:15 +00:00
|
|
|
tmp_output=/var/run/periodic.$$
|
1997-08-12 17:48:49 +00:00
|
|
|
|
1997-08-13 06:02:18 +00:00
|
|
|
# Execute each executable file in the directory list. If the x bit is not
|
1997-08-12 17:48:49 +00:00
|
|
|
# set, assume the user didn't really want us to muck with it (it's a
|
|
|
|
# README file or has been disabled).
|
|
|
|
|
2000-09-14 17:19:15 +00:00
|
|
|
for dir in $dirlist
|
|
|
|
do
|
|
|
|
eval output=\$${dir##*/}_output
|
|
|
|
case "$output" in
|
|
|
|
/*) pipe="cat >>$output";;
|
|
|
|
*) pipe="mail -s '$host ${dir##*/} run output' ${output:-root}";;
|
|
|
|
esac
|
|
|
|
|
|
|
|
success=YES info=YES badconfig=NO # Defaults when ${run}_* aren't YES/NO
|
|
|
|
for var in success info badconfig
|
|
|
|
do
|
|
|
|
case $(eval echo "\$${dir##*/}_show_$var") in
|
|
|
|
[Yy][Ee][Ss]) eval $var=YES;;
|
|
|
|
[Nn][Oo]) eval $var=NO;;
|
|
|
|
esac
|
1997-08-13 06:02:18 +00:00
|
|
|
done
|
2000-09-14 17:19:15 +00:00
|
|
|
|
|
|
|
for file in $dir/*
|
|
|
|
do
|
|
|
|
if [ -x $file -a ! -d $file ]
|
|
|
|
then
|
|
|
|
$file </dev/null >$tmp_output 2>&1
|
|
|
|
case $? in
|
|
|
|
0) [ $success = YES ] && cat $tmp_output;;
|
|
|
|
1) [ $info = YES ] && cat $tmp_output;;
|
|
|
|
2) [ $badconfig = YES ] && cat $tmp_output;;
|
|
|
|
*) cat $tmp_output;;
|
|
|
|
esac
|
|
|
|
rm -f $tmp_output
|
|
|
|
fi
|
|
|
|
done | eval $pipe
|
1997-08-13 06:23:54 +00:00
|
|
|
done
|