periodic.sh revision 28424
1#!/bin/sh -
2#
3# $Id: periodic.sh,v 1.4 1997/08/16 17:08:35 pst Exp $
4#
5# Run nightly periodic scripts
6#
7# usage: periodic { daily | weekly | monthly } - run standard periodic scripts
8#        periodic /absolute/path/to/directory  - run periodic scripts in dir
9#
10
11usage () {
12    echo "usage: $0 <directory of files to execute>" 1>&2
13    echo "or     $0 { daily | weekly | monthly }"    1>&2
14    exit 1
15}
16
17if [ $# -lt 1 ] ; then
18    usage
19fi
20
21# If possible, check /etc/rc.conf to see if there are additional dirs to check
22if [ -r /etc/rc.conf ] ; then
23    . /etc/rc.conf
24fi
25
26dir=$1
27run=`basename $dir`
28
29# If a full path was not specified, check the standard cron areas
30
31if [ "$dir" = "$run" ] ; then
32    dirlist=""
33    for top in /etc/periodic ${local_periodic} ; do
34	if [ -d $top/$dir ] ; then
35	    dirlist="${dirlist} $top/$dir"
36	fi
37    done
38
39# User wants us to run stuff in a particular directory
40else
41   for dir in $* ; do
42       if [ ! -d $dir ] ; then
43	   echo "$0: $dir not found" 1>&2
44	   exit 1
45       fi
46   done
47
48   dirlist="$*"
49fi
50
51host=`hostname -s`
52echo "Subject: $host $run run output"
53
54# Execute each executable file in the directory list.  If the x bit is not
55# set, assume the user didn't really want us to muck with it (it's a
56# README file or has been disabled).
57
58for dir in $dirlist ; do
59    for file in $dir/* ; do
60	if [ -x $file ] ; then
61	    $file
62	fi
63    done
64done
65