summaryrefslogtreecommitdiffstats
path: root/usr.sbin/periodic/periodic.sh
diff options
context:
space:
mode:
Diffstat (limited to 'usr.sbin/periodic/periodic.sh')
-rw-r--r--usr.sbin/periodic/periodic.sh82
1 files changed, 59 insertions, 23 deletions
diff --git a/usr.sbin/periodic/periodic.sh b/usr.sbin/periodic/periodic.sh
index fb618db..e7a4200 100644
--- a/usr.sbin/periodic/periodic.sh
+++ b/usr.sbin/periodic/periodic.sh
@@ -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
-
-if [ ! -d $dir ] ; then
- ( echo "$0: $dir not found"
- echo ""
- echo "usage: $0 <directory of files to execute>"
- ) 1>&2
- exit 1
-fi
+ dirlist=""
+ for top in /etc/cron.d ${local_cron} ; do
+ if [ -d $top/$dir ] ; then
+ dirlist="${dirlist} $top/$dir"
+ fi
+ done
-# Check and see if there is work to be done, if not, exit silently
-# this is not an error condition.
+# 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
-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
OpenPOWER on IntegriCloud