Loading...
X

How to list all Cron tasks

Show all Cron jobs for all users

To display every item in the cron schedule for each user, use the following command:

for user in $(cut -f1 -d: /etc/passwd); do sudo crontab -u $user -l 2>/dev/null | grep -v '^#'; done

Elevated privileges are required to display information about all users – otherwise, only the current user's schedule will be shown.

The previous command suppresses error output so as not to display messages like “no crontab for mysql”, so if you need to display all messages for debugging, then use the following command:

for user in $(cut -f1 -d: /etc/passwd); do sudo crontab -u $user -l | grep -v '^#'; done

When users are defined in NIS or LDAP, then /etc/passwd must be replaced with the getent command, that is, the following command must be used:

for user in $(getent passwd | cut -f1 -d: ); do echo $user; sudo crontab -u $user -l; done

All Cron files

The location of the scheduling cron files differs from distribution to distribution. To display information from all possible cron files, use the following command:

grep '*' --color /etc/anacrontab /var/spool/cron/crontabs/* /var/spool/cron/* /etc/cron.hourly/* /etc/cron.daily/* /etc/cron.weekly/* /etc/cron.monthly/* /etc/cron.d/* /etc/init.d/down 2>/dev/null

A variant of this command, which will display absolutely all lines in these files:

grep '.*' --color /etc/anacrontab /var/spool/cron/crontabs/* /var/spool/cron/* /etc/cron.hourly/* /etc/cron.daily/* /etc/cron.weekly/* /etc/cron.monthly/* /etc/cron.d/* /etc/init.d/down 2>/dev/null

This command will display the name and contents of all files in the specified locations, while errors like “cannot open '/etc/cron.daily/*' for reading: No such file or directory” will not be displayed.


Leave Your Observation

Your email address will not be published. Required fields are marked *