Making crontab more manageable, something I've definitely dreamed of many times. When it comes down to it though, if you need 20 scripts to be scheduled to run - well - you need 20 scripts to be scheduled to run.
The primary issue, at least for me, has always been creating a new entry in /etc/crontab
(or in a user's crontab -e
). Especially when these new entries are set to run at the same time as an existing entry (or even a list of entries).
Say, for instance, you needed 5 different scripts to run on-the-hour every-hour. You could create 5 different entries in crontab for this - or - you can take advantage of run-parts
. run-parts
allows you to specify a crontab entry just like any other entry, but the "command" is actually a directory. When it's the command's time to execute, it will execute every script in the given directory.
Here's a list that are common to linux systems:
01 * * * * root run-parts /etc/cron.hourly
02 4 * * * root run-parts /etc/cron.daily
22 4 * * 0 root run-parts /etc/cron.weekly
42 4 1 * * root run-parts /etc/cron.monthly
In the first line, /etc/cron.hourly
states that every hour at 1-minute-past-the-hour (01 * * * *
), all of the scripts that are located in the /etc/cron.hourly
directory will be executed. The same concept is applied to the other lines as well. You're not limited to these times and directories either - you can fully customize them to suit your needs as a standard crontab entry.
Other than batching-scripts by directories with run-parts
, you can make things more manageable by separating them by "users" and putting them into each user's crontab via crontab -u username -e
. Say, for instance, you have a handful of scripts specific to reporting, you could create a "reportRunner" user and assign all report-related crons to that user. Doing this, you'll easily have list-separation and it would be easy to manage the different categories of scripts/schedules (in my opinion). It won't make the total list of crons shorter, but it should help make any-given list you're looking at shorter (and categorized).
crontab -e