Cron has been popular for decades because it's easy to use and available everywhere. The downside to this flexibility is that cron job maintenance and debugging can be a real headache. In this guide we explore the 5 different places you can find cron jobs on your server.
In Linux, each user has their own crontab that can be used to schedule jobs that will be run as that user. You can view, update and delete a user crontab file using the
Viewing your user crontab
$ crontab -l 0 9 * * * /var/cronitor/bin/water-the-plants.py 0 7 * * 6 /var/cronitor/bin/take-out-the-garbage.py
Viewing another user's crontab
$ crontab -u tstark -l 0 0 * * * /jarvis/reboot-arc-reactor
Knowing where to look
If your server has a lot of users it could be challenging to find the right one. If you can see the job details in your cron logs, the username may be included. For example, here i can see the ubuntu user running the database backup script:
Aug 5 4:05:01 dev01 CRON: (ubuntu) CMD (/var/cronitor/database-backup.sh)
Tip:The user crontab is the easiest place to add a job so it’s commonly used and is the first place to look when you’re trying to locate a cron job.
Tip:To update a user crontab, use
crontab -e. The cron files themselves should not be updated directly. Using crontab -e will validate your changes and signal cron to reload your file.
Like any other user, root has a user crontab. Essentially the same as any other user crontab, you are editing the root crontab when you run
sudo crontab -e.
Jobs scheduled in the root user crontab will be executed as root with all of its privileges.
If your system has
/etc/cron.monthly directories, these
can be used to schedule jobs by copying or symlinking a script or command.
In distributions like Ubuntu, you can see when these scripts will be invoked by looking
for lines in
$ head /etc/crontab 7 * * * * root cd / && run-parts — report /etc/cron.hourly 5 23 * * * root cd / && run-parts — report /etc/cron.daily 5 23 * * 7 root cd / && run-parts — report /etc/cron.weekly 5 23 1 * * root cd / && run-parts — report /etc/cron.monthly
The original and still commonly used way to schedule system-wide cron jobs is by adding entries to the crontab file
$ tail /etc/crontab * 0 * * * dataproc /var/cronitor/bin/database-backup.sh
Another common way to schedule system-wide cron jobs is by adding a crontab file to
Like jobs scheduled in /etc/crontab, writing to /etc/cron.d requires elevated privileges and the first word after the expression of each cron job must specify which user will run the job.
Tip:For installers and scripts, adding a file to /etc/cron.d is a much cleaner option than adding entries to crontab files.
When individual user crontabs are edited using
crontab -e, the crontab files themselves are stored in
You can look, but avoid the temptation to edit crontab files here directly and always use
If you edit files in /var/spool/cron directly you will lose the benefit of syntax checking that the crontab editor provides and your changes will not be detected without sending a reload signal to the cron daemon.
Our software, CronitorCLI, includes the free tools we always wished we had.
Scan your system and list every cron job in seconds using
cronitor list. Run any cron job instantly using
Get Started Free