diff options
author | brian <brian@FreeBSD.org> | 2000-09-14 17:19:15 +0000 |
---|---|---|
committer | brian <brian@FreeBSD.org> | 2000-09-14 17:19:15 +0000 |
commit | 4484d23ba731b5a116bedf7b28421514aa70f53b (patch) | |
tree | c37ec10ec51a7430c5a8044972107e92a18f16b0 /usr.sbin/periodic/periodic.sh | |
parent | d63a19c1e21807290eba99997d2935286893fede (diff) | |
download | FreeBSD-src-4484d23ba731b5a116bedf7b28421514aa70f53b.zip FreeBSD-src-4484d23ba731b5a116bedf7b28421514aa70f53b.tar.gz |
Another overhaul of the periodic stuff.
All periodic sub-scripts <larf> now have their return codes interpreted
by periodic(8). Output may be masked based on variable values in
periodic.conf.
It's also now possible to email periodic output to arbitrary addresses,
or to send it to a log file, examples of which can be found in
newsyslog.conf.
The upshot of it all should be no discernable changes to the default
behaviour of periodic(8).
PR: 21250
Diffstat (limited to 'usr.sbin/periodic/periodic.sh')
-rw-r--r-- | usr.sbin/periodic/periodic.sh | 76 |
1 files changed, 49 insertions, 27 deletions
diff --git a/usr.sbin/periodic/periodic.sh b/usr.sbin/periodic/periodic.sh index 7141710..f3b5d22 100644 --- a/usr.sbin/periodic/periodic.sh +++ b/usr.sbin/periodic/periodic.sh @@ -25,43 +25,65 @@ if [ -r /etc/defaults/periodic.conf ]; then source_periodic_confs fi -dir=$1 -run=`basename $dir` +dirlist= # If a full path was not specified, check the standard cron areas -if [ "$dir" = "$run" ] ; then - dirlist="" - for top in /etc/periodic ${local_periodic} ; do - if [ -d $top/$dir ] ; then - dirlist="${dirlist} $top/$dir" - fi - done - -# User wants us to run stuff in a particular directory -else - for dir in $* ; do - if [ ! -d $dir ] ; then - echo "$0: $dir not found" 1>&2 - exit 1 - fi - done - - dirlist="$*" -fi +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 host=`hostname` export host -echo "Subject: $host $run run output" +tmp_output=/var/run/periodic.$$ # Execute each executable file in the directory list. If the x bit is not # set, assume the user didn't really want us to muck with it (it's a # README file or has been disabled). -for dir in $dirlist ; do - for file in $dir/* ; do - if [ -x $file -a ! -d $file ] ; then - $file - fi +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 done + + 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 done |