3 # $FreeBSD: head/usr.sbin/periodic/periodic.sh 326041 2017-11-20 23:51:51Z asomers $
5 # Run nightly periodic scripts
7 # usage: periodic { daily | weekly | monthly | security } - run standard scripts
8 # periodic /absolute/path/to/directory - run periodic scripts in dir
12 echo "usage: $0 <directory of files to execute>" 1>&2
13 echo "or $0 { daily | weekly | monthly | security }" 1>&2
19 # Where's our output going ?
20 eval output
=\$
${1##*/}_output
22 /*) pipe
="cat >>$output";;
24 *) pipe
="mail -E -s '$host ${2}${2:+ }${1##*/} run output' $output";;
29 if [ $# -lt 1 ] ; then
33 # If possible, check the global system configuration file,
34 # to see if there are additional dirs to check
35 if [ -r /etc
/defaults
/periodic.conf
]; then
36 .
/etc
/defaults
/periodic.conf
43 # If we were called normally, then create a lock file for each argument
44 # in turn and reinvoke ourselves with the LOCKED argument. This prevents
45 # very long running jobs from being overlapped by another run as this is
46 # will lead the system running progressivly slower and more and more jobs
48 if [ $1 != "LOCKED" ]; then
51 lockfile
=/var
/run
/periodic.
${arg##*/}.lock
52 lockf
-t 0 "${lockfile}" /bin
/sh
$0 LOCKED
"$arg"
56 echo "can't create ${lockfile}" | \
57 output_pipe
$arg "$PERIODIC"
61 echo "$host ${arg##*/} prior run still in progress" | \
62 output_pipe
$arg "$PERIODIC"
79 if [ -z "$PERIODIC_ANTICONGESTION_FILE" ] ; then
80 export PERIODIC_ANTICONGESTION_FILE
=`mktemp ${TMPDIR:-/tmp}/periodic.anticongestion.XXXXXXXXXX`
82 if tty
> /dev
/null
2>&1; then
83 export PERIODIC_IS_INTERACTIVE
=1
85 tmp_output
=`mktemp ${TMPDIR:-/tmp}/periodic.XXXXXXXXXX`
87 export PERIODIC
="$arg${PERIODIC:+ }${PERIODIC}"
89 # Execute each executable file in the directory list. If the x bit is not
90 # set, assume the user didn't really want us to muck with it (it's a
91 # README file or has been disabled).
93 success
=YES info
=YES badconfig
=NO empty_output
=YES
# Defaults when ${run}_* aren't YES/NO
94 for var
in success info badconfig empty_output
; do
95 case $
(eval echo "\$${arg##*/}_show_$var") in
96 [Yy
][Ee
][Ss
]) eval $var=YES
;;
97 [Nn
][Oo
]) eval $var=NO
;;
102 /*) if [ -d "$arg" ]; then
105 echo "$0: $arg not found" >&2
110 for top
in /etc
/periodic
${local_periodic}; do
111 [ -d $top/$arg ] && dirlist
="$dirlist $top/$arg"
119 for dir
in $dirlist; do
120 for file in $dir/*; do
121 if [ -x $file -a ! -d $file ]; then
123 processed
=$
(($processed + 1))
124 $file </dev
/null
>$tmp_output 2>&1
126 if [ -s $tmp_output ]; then
128 0) [ $success = NO
] && output
=FALSE
;;
129 1) [ $info = NO
] && output
=FALSE
;;
130 2) [ $badconfig = NO
] && output
=FALSE
;;
132 [ $output = TRUE
] && { cat $tmp_output; empty
=FALSE
; }
134 cp /dev
/null
$tmp_output
138 if [ $empty = TRUE
]; then
139 if [ $empty_output = TRUE
]; then
140 [ $processed = 1 ] && plural
= || plural
=s
141 echo "No output from the $processed file$plural processed"
145 echo "-- End of $arg output --"
147 } | output_pipe
$arg "$context"
150 rm -f $PERIODIC_ANTICONGESTION_FILE