Organizing cronjobs in your crontab

Conventions in a crontab file? Yes, because no one likes code or system cruft. Here's an organization guide for your cronjob-crontab file.

Organizing cronjobs in your crontab

Why this? Fair question, really. So picture one scenario where things can go out of hand, pretty quickly. One server, 2+ devs, one or more applications. Backup scripts, maintenance cronjobs, scheduled exports... Soon your crontab file can turn into spaghetti.

Here's an approach that works for the editor(s). The conventions have been deliberately kept simple. After all, frameworks and standards come with their own set of headaches.

For the uninitiated, bring up your cronjob editor with this command

crontab -e

Let's setup a few cronjobs, for a hypothetical analytics project. (This simply collects data from a vehicle tracking device and provides a dashboard with cool/interesting data.)

# StatsMaster ([email protected]) on 2021-09-23
## geofence-pointaggregator ([email protected]) on 2022-01-16
0 6  *  *  *  /var/app/ > /var/app/sm-geof.log

## notifier-anomalyreport ([email protected]) on 2022-04-19
*  *  *  *  /var/app/ > /var/app/sm-anomreport.log

Here are the conventions followed

# <app-name> (edit@first_name.last_name) on YYYY-MM-DD
## <module1-name-purpose> (edit@first_name.last_name) on YYYY-MM-DD
 *  *  *  *  /var/app/ > /var/app/script.log (double space between * *)

## <module2-name-purpose> (edit@first_name.last_name) on YYYY-MM-DD
 *  *  *  *  /var/app/ > /var/app/script.log (double space between * *)


app-name : This would be your project name
edit : This indicates the last edited time along with the editor
first_name.last_name : This is obvious
YYYY-MM-DD : Obvious again, date indicator. Tack on the time, if required.

Common Cronjob commands

This installs a new crontab or updates job in an existing crontab

$ crontab -e

View a list of Crontab entries

$ crontab -l

View a list of Crontab entries for a specific user

$ crontab -u username -l
$ crontab -u lisav -l

Uninstall jobs from crontab

$ crontab -r

This allows you to edit the crontab of another user by mentioning the username

$ crontab -u username -e

$ crontab -u lisav -e