Helper to run a number of jobs in a directory, similar to run-parts, but I did it my way.
Find a file
2020-05-02 14:42:26 +02:00
README.md some README revision 2020-05-02 14:42:26 +02:00
run-jobs change re-exec marker to work under Linux 2020-05-02 13:46:43 +02:00

Run jobs in a directory

$ run-jobs directory

run-jobs, called with a single command-line parameter, a directory pathname, runs all executable programs (jobs) in that directory, in order, except those whose name starts with # or ends with ~. If one of these jobs prints something to stdout or stderr, or exits with a non-zero status, this is printed to stdout along with a time stamp and the program's pathname.

Before starting to run the jobs, the process environment is set from a /bin/sh script $HOME/.environment. All actions and output are logged to $HOME/var/log/run-jobs.log (or, for root, /var/log/run-jobs.log).

Using a configuration file $HOME/.run-jobs.conf (in Python syntax), the behaviour can be modified by setting these configuration variables:

debug: if true, print extensive debug output (default: False)

environment: the pathname of the environment file (default: "$HOME/.environment")

log: the pathname of the log file (default: "$HOME/var/log/run-jobs.log" (or, for root, "/var/log/run-jobs.log")

mailto: if true, an email address to send the output to (default: False)

mail_sender: if true, the email sender address; otherwise the same as mailto (default: None)

job_args: array of command-line arguments to be passed to the jobs (default: [])

sendmail_call: command line to send the email message, if any (default: ["/usr/sbin/sendmail", "-t", "-oi"])

stdout: if true, print status information to standard output (default: True)

timeformat: timestamp format for status output and log file (default: "%Y%m%d:%H%M%S")

verbose: if true, print more verbose info about all actions done as in the log file (default: False)

Originally, this program was a rather simple shell script to run cron or startup jobs in a directory (think /etc/rc.local.d/). When macOS's cron stopped sending email notifications for cron job output with the Catalina release (for reasons I haven't learned yet), I felt the need to do this by myself. At that point it seemed sensible to also include the information which job had printed the output, and when, and also to make it suited to the different types of cron behaviour.

My own crontab looks like this:

0  *  *  *  *         $HOME/bin/run-jobs $HOME/etc/periodic/hourly
17 2  *  *  *         $HOME/bin/run-jobs $HOME/etc/periodic/daily
27 5  *  *  0         $HOME/bin/run-jobs $HOME/etc/periodic/weekly
27 3  *  *  1         $HOME/bin/run-jobs $HOME/etc/periodic/mondays
23 5  1  *  *         $HOME/bin/run-jobs $HOME/etc/periodic/monthly

Standard BSD license applies.

[ni@w21.org 2020-05-02]