Incorporate some ideas that came up during discussion with msmith.

This commit is contained in:
Paul Traina 1997-08-13 06:02:18 +00:00
parent 1e3d7510d3
commit fb1485d3e3
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=28143
2 changed files with 109 additions and 50 deletions

View File

@ -22,7 +22,7 @@
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
.\" $Id$
.\" $Id: periodic.8,v 1.1.1.1 1997/08/12 17:48:49 pst Exp $
.\"
.Dt periodic 8
.Os FreeBSD 3.0
@ -31,52 +31,69 @@
.Nd run periodic system functions
.Sh SYNOPSIS
.Nm periodic
.Ar path-to-directory
.Ao
.Cm daily | weekly | monthly |
.Ar path Op path ...
.Ac
.Sh DESCRIPTION
The
.Nm
program is intended to be called by cron(8) to execute shell scripts
located in the specified directory.
.Pp
The arguments are as follows:
One, and only one, of the following arguments should be specified:
.Bl -tag -width Fl
.It Cm daily
Perform the standard daily periodic executable run.
This usually occurs early in the morning (local time).
.It Cm weekly
Perform the standard weekly periodic executable run.
This usually occurs on Sunday mornings.
.It Cm monthly
Perform the standard monthly periodic executable run.
This usually occurs on the first day of the month.
.It Ar path
The
.Ar path
is a required argument. This is a path to a directory containing
executable programs or shell scripts which are executed one by one
in alphanumeric order.
An absolute path to a directory containing a set of executables to be run.
.El
.Pp
The
.Nm
program will run each executable file in the directory or directories
specified. If a file does not have the executable bit set, it will be
ignored silently.
.Sh ENVIRONMENT
The
.Nm
command sets the
.Ev PATH
environment to include all standard system
directories. If entries are added, each entry
must be responsible for configuring the appropriate environment.
environment to include all standard system directories, but no additional
directories, such as
.Pa /usr/local/bin .
If executables are added which depend upon other path components, each
executable must be responsible for configuring its own appropriate environment.
.Sh FILES
.Bl -tag -width /etc/cron.d/monthly
.Bl -tag -width /etc/crontab
.It Pa /etc/crontab
The
.Nm
program is typically called via entries in the system default cron table.
.It Pa /etc/cron.d
The default top-level directory where periodic script directories reside.
If a simple name, rather than a complete path, is specified on the command
line, this directory is checked for the corresponding argument.
.It Pa /etc/cron.d/daily
The default directory where script fragments that should be executed once
a day (usually in the middle of the night) are placed.
.It Pa /etc/cron.d/weekly
The default directory where script fragments that should be executed once
a eek (usually on a weekend night) are placed.
.It Pa /etc/cron.d/monthly
The default directory where script fragments that should be executed once
a month (usually on the first day of the month) are placed.
.It Pa <entry>
Each file in the specified directory is checked for executability. If
the execute bit is set, the entry is run.
The top level directory containing
.Pa daily ,
.Pa weekly ,
and
.Pa monthly
subdirectories which contain standard system periodic executables.
.It Pa /etc/rc.conf
The
.Pa rc.conf
system registry contains a variable
.Va local_cron
which may be configured to specify additional top level standard
periodic directories, such as
.Pa /usr/local/etc/cron.d
and
.Pa /usr/X11R6/etc/cron.d .
.El
.Sh EXAMPLES
The system crontab should have entries for
@ -87,9 +104,15 @@ similar to the following example:
.Dl 0 2 * * * root periodic daily 2>&1
.Dl 0 3 * * 6 root periodic weekly 2>&1
.Dl 0 5 1 * * root periodic monthly 2>&1
.Pp
Additionally, the system registry will typically have a
.Va local_cron
variable reading:
.Dl local_cron="/usr/local/etc/cron.d /usr/X11R6/etc/cron.d" # cron script dirs.
.Sh SEE ALSO
.Xr cron 8
.Xr crontab 5 ,
.Xr rc.conf 5 ,
.Xr sh 1 ,
.Rs
.Sh DIAGNOSTICS

View File

@ -1,6 +1,6 @@
#!/bin/sh -
#
# $Id$
# $Id: periodic.sh,v 1.1.1.1 1997/08/12 17:48:49 pst Exp $
#
# Run nightly periodic scripts
#
@ -8,44 +8,80 @@
# periodic /absolute/path/to/directory - run periodic scripts in dir
#
if [ $# -lt 1 ] ; then
usage () {
echo "usage: $0 <directory of files to execute>" 1>&2
echo "or $0 { daily | weekly | monthly }" 1>&2
exit 1
}
if [ $# -lt 1 ] ; then
usage
fi
# If possible, check /etc/rc.conf to see if there are additional dirs to check
if [ -r /etc/rc.conf ] ; then
. /etc/rc.conf
fi
dir=$1
run=`basename $dir`
# If a full path was not specified, assume default cron area
# If a full path was not specified, check the standard cron areas
if [ "$dir" = "$run" ] ; then
dir="/etc/cron.d/$dir"
fi
dirlist=""
for top in /etc/cron.d ${local_cron} ; do
if [ -d $top/$dir ] ; then
dirlist="${dirlist} $top/$dir"
fi
done
if [ ! -d $dir ] ; then
( echo "$0: $dir not found"
echo ""
echo "usage: $0 <directory of files to execute>"
) 1>&2
exit 1
fi
# 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
# Check and see if there is work to be done, if not, exit silently
# this is not an error condition.
if [ "`basename $dir/*`" = "*" ] ; then
exit 0
dirlist="$*"
fi
host=`hostname -s`
echo "Subject: $host $run run output"
# Execute each executable file in the directory. If the x bit is not
# 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 file in $dir/* ; do
if [ -x $file ] ; then
$file
fi
done
# We can't run scripts in order if we don't have sort and sed, which
# might not be present on an embedded system.
if [ -x /usr/bin/sort -a -x /usr/bin/sed ] ; then
# Sort files in ascending alphanumeric order based on their basename
# across all directories. XXX scripts better not have ':' in their names!
for file in `(
for dir in $dirlist ; do
for file in $dir/* ; do
echo $file | sed -e 's;\(.*\)/\([^/]*$\);\2:\1;'
done
done
) | sort | sed -e 's; *\([^:]*\):\([^ ]*\);\2/\1 ;g' `; do
if [ -x $file ] ; then
$file
fi
done
else
# Just run scripts in order in each directory.
for dir in $dirlist ; do
for file in $dir/* ; do
if [ -x $file ] ; then
$file
fi
done
done
fi