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