Linux: List crontabs for all Users

Sometimes you want to see all cron jobs installed in the system.
You can list the content of a user’s crontab with the following command (run as root):

# crontab -u username -l

What’s displayed here is the content of the crontab file for this user in /var/spool/cron/crontabs. If you omit the -u option, it will assume the current user.

So basically to display all crontabs for all users, you just need to write the following:

# cat /var/spool/cron/crontabs/*

This shows all crontabs but unfortunately you can’t see anymore for which user. To display the filename before it’s contents use the following:

# find /var/spool/cron/crontabs/ -type f -print | while read filename; do echo "$filename"; cat "$filename"; done

An alternative is to just do the opposite: instead of going through the files and printing the user, you could go through all users and then print the file for this user.

First you need the username of all users:

# cat /etc/passwd | awk -F: '{ print $1; }'

Then print for each user the corresponding crontab file if it exists:

# cat /etc/passwd | awk -F: '{ print $1; }' | while read user; do crontab -u $user -l 2>/dev/null | awk '{ print "'$user':"$0; }'; done

Now there’s still something missing. Using the crontab command, you only see one part of the truth. Actually there are other cron jobs not configured in crontab. They are stored in /etc/cron.*.

/etc/cron.d: each file in this directory contains additional cron tasks.

/etc/cron.daily, /etc/cron.hourly, /etc/cron.monthly, /etc/cron.weekly: the files there are called from the file /etc/crontab which “includes” them using:

run-parts --report /etc/cron.XXX

One thought on “Linux: List crontabs for all Users

Leave a Reply

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