summaryrefslogtreecommitdiffstats
path: root/usr.sbin/periodic/periodic.sh
blob: 593d6c5ad8b4a9f750e9f2b9217daf0dce3067e6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#!/bin/sh -
#
# $Id: periodic.sh,v 1.4 1997/08/16 17:08:35 pst Exp $
#
# Run nightly periodic scripts
#
# usage: periodic { daily | weekly | monthly } - run standard periodic scripts
#        periodic /absolute/path/to/directory  - run periodic scripts in dir
#

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, check the standard cron areas

if [ "$dir" = "$run" ] ; then
    dirlist=""
    for top in /etc/periodic ${local_periodic} ; do
	if [ -d $top/$dir ] ; then
	    dirlist="${dirlist} $top/$dir"
	fi
    done

# 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

   dirlist="$*"
fi

host=`hostname -s`
echo "Subject: $host $run run output"

# 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 dir in $dirlist ; do
    for file in $dir/* ; do
	if [ -x $file ] ; then
	    $file
	fi
    done
done
OpenPOWER on IntegriCloud