How can get a list of all scheduled cron jobs on my machine?

My sysadmin has set up a bunch of cron jobs on my machine. I’d like to know exactly what is scheduled for what time. How can I get that list?

Answers:

Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.

Method 1

With most Crons (e.g. Vixie-Cron – Debian/Ubuntu default, Cronie – Fedora default, Solaris Cron …) you get the list of scheduled cron jobs for the current user via:

$ crontab -l

or for another user via

# crontab -l -u juser

To get the crontabs for all users you can loop over all users and call this command.

Alternatively, you can look up the spool files. Usually, they are are saved under /var/spool/cron, e.g. for vcron following directory

/var/spool/cron/crontabs

contains all the configured crontabs of all users – except the root user who is also able to configure jobs via the system-wide crontab, which is located at

/etc/crontab

With cronie (default on Fedora/CentOS), there is a .d style config directory for system cron jobs, as well:

/etc/cron.d

(As always, the .d directory simplifies maintaining configuration entries that are part of different packages.)

For convenience, most distributions also provide a directories where linked/stored scripts are periodically executed, e.g.:

/etc/cron.daily
/etc/cron.hourly
/etc/cron.monthly
/etc/cron.weekly

The timely execution of those scripts is usually managed via run-parts entries in the system crontab or via anacron.

With Systemd (e.g. on Fedora, CentOS 7, …) periodic job execution can additionally be configured via timer units. The enabled system timers can be displayed via:

$ systemctl list-timers

Note that users beside root may have user systemd instances running where timers are configured, as well. For example, on Fedora, by default, a user systemd instance is started for each user that is currently logged in. They can be recognized via:

$ ps aux | grep 'systemd[ ]--user'

Those user timers can be listed via:

$ systemctl --user list-timers

An alternative to issuing the list-timers command is to search for timer unit files (pattern: *.timer) and symbolic links to them in the usual system and user systemd config directories:

$ find /usr/lib/systemd/ /etc/systemd -name '*.timer'
$ find /home '(' -path '/home/*/.local/share/systemd/user/*' 
              -o -path '/home/*/.config/systemd/*' ')' 
      -name '*.timer'  2> /dev/null

(As with normal service units, a timer unit is enabled via creating a symbolic link in the right systemd config directory.)

See also:

Method 2

Depending on how your linux system is set up, you can look in:

  • /var/spool/cron/* (user crontabs)
  • /etc/crontab (system-wide crontab)

also, many distros have:

  • /etc/cron.d/*
    These configurations have the same syntax as /etc/crontab
  • /etc/cron.hourly, /etc/cron.daily, /etc/cron.weekly, /etc/cron.monthly

These are simply directories that contain executables that are executed hourly, daily, weekly or monthly, per their directory name.

On top of that, you can have at jobs (check /var/spool/at/*), anacron (/etc/anacrontab and /var/spool/anacron/*) and probably others I’m forgetting.

Method 3

To list all crons for the given user.

crontab -u username -l;

To list all crons for all users

Run it as a super user

#!/bin/bash
#List all cron jobs for all users
for user in `cat /etc/passwd | cut -d":" -f1`;
do 
crontab -l -u $user;
done

Method 4

You can list all cron jobs with (I’m using more to list the location in the output):

sudo sh -c 'more /etc/crontab /etc/cron.d/* /var/spool/cron/crontabs/* 2>/dev/null' | less

Or without comments:

sudo sh -c 'more /etc/crontab /etc/cron.d/* /var/spool/cron/crontabs/* 2>/dev/null' 
   | grep "^s*[^#]"

crontab has entries to run the scripts in cron.hourly, daily, weekly and monthly – you can list those with:

ls /etc/cron.hourly /etc/cron.daily /etc/cron.weekly /etc/cron.monthly


All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x