periodic.sh revision 28112
1#!/bin/sh -
2#
3# $Id$
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
11if [ $# -lt 1 ] ; then
12    echo "usage: $0 <directory of files to execute>" 1>&2
13    exit 1
14fi
15
16dir=$1
17run=`basename $dir`
18
19# If a full path was not specified, assume default cron area
20
21if [ "$dir" = "$run" ] ; then
22    dir="/etc/cron.d/$dir"
23fi
24
25if [ ! -d $dir ] ; then
26    ( echo "$0: $dir not found"
27      echo ""
28      echo "usage: $0 <directory of files to execute>"
29    ) 1>&2
30    exit 1
31fi
32
33# Check and see if there is work to be done, if not, exit silently
34# this is not an error condition.
35
36if [ "`basename $dir/*`" = "*" ] ; then
37    exit 0
38fi
39
40host=`hostname -s`
41echo "Subject: $host $run run output"
42
43# Execute each executable file in the directory.  If the x bit is not
44# set, assume the user didn't really want us to muck with it (it's a
45# README file or has been disabled).
46
47for file in $dir/* ; do
48    if [ -x $file ] ; then
49	$file
50    fi
51done
52