How to list the active cronjobs in Linux
Written by Guillermo Garron
Date: 2020-06-02 20:45:00 00:00
Part of the maintenance tasks of a Linux system are repetitive, fortunately Linux offers you cronjobs.
What are cronjobs?
Cron jobs are repetitive tasks executed by the cron daemon, and a deamon is a program that runs all the time in a Linux system, so cron deamon takes care of these tasks and execute them according to an schedule.
Years ago I have written a more complete guide to crontab and cron job, let's now focus on listing them.
crontab -l
Will list the cronjobs for the current user, but what about other user's cronjobs?
You will have to be root or have sudo powers in order to list other users' cronjobs
sudo crontab -u username -l
But how to know which users have scheduled cronjobs?
Linux has a spool folder for scheduled jobs, being them cron deamon's jobs, or printer jobs.
sudo ls -1 /var/spool/cron/crontabs
That command will list all users with active cronjobs, then you can use sudo crontab -u username -l
to know the cronjobs of an specific users.
Crontab file
In Debian like systems, you will find a useful structure to add jobs to be executed daily, weekly or monthly.
Below see /etc/crontab
file in Ubuntu.
# Example of job definition:
# .---------------- minute (0 - 59)
# | .------------- hour (0 - 23)
# | | .---------- day of month (1 - 31)
# | | | .------- month (1 - 12) OR jan,feb,mar,apr ...
# | | | | .---- day of week (0 - 6) (Sunday=0 or 7) OR sun,mon,tue,wed,thu,fri,sat
# | | | | |
# * * * * * user-name command to be executed
17 * * * * root cd / && run-parts --report /etc/cron.hourly
25 6 * * * root test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.daily )
47 6 * * 7 root test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.weekly )
52 6 1 * * root test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.monthly )
#
As it can be seen, every day the file /etc/cron.daily
is executed, and every week the /etc/cron.weekly
file is executed, and every month the file /etc/cron.monthly
is executed. Inside those files you can add (as root) any task you need to execute according to those periods of time.