xref: /freebsd/usr.sbin/periodic/periodic.sh (revision 23f282aa31e9b6fceacd449020e936e98d6f2298)
1#!/bin/sh -
2#
3# $FreeBSD$
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 the global system configuration file,
22# to see if there are additional dirs to check
23if [ -r /etc/defaults/rc.conf ]; then
24    . /etc/defaults/rc.conf
25    source_rc_confs
26elif [ -r /etc/rc.conf ]; then
27    . /etc/rc.conf
28fi
29
30dir=$1
31run=`basename $dir`
32
33# If a full path was not specified, check the standard cron areas
34
35if [ "$dir" = "$run" ] ; then
36    dirlist=""
37    for top in /etc/periodic ${local_periodic} ; do
38	if [ -d $top/$dir ] ; then
39	    dirlist="${dirlist} $top/$dir"
40	fi
41    done
42
43# User wants us to run stuff in a particular directory
44else
45   for dir in $* ; do
46       if [ ! -d $dir ] ; then
47	   echo "$0: $dir not found" 1>&2
48	   exit 1
49       fi
50   done
51
52   dirlist="$*"
53fi
54
55host=`hostname`
56export host
57echo "Subject: $host $run run output"
58
59# Execute each executable file in the directory list.  If the x bit is not
60# set, assume the user didn't really want us to muck with it (it's a
61# README file or has been disabled).
62
63for dir in $dirlist ; do
64    for file in $dir/* ; do
65	if [ -x $file -a ! -d $file ] ; then
66	    $file
67	fi
68    done
69done
70