How to list all Cron tasks
October 15, 2021
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.
Related articles:
- How to use Kali Linux to check web-sites (50%)
- How to run small Python code in Bash (50%)
- How to completely uninstall a package along with dependencies on Arch Linux (as well as BlackArch and Manjaro) (50%)
- Analogue of the --force option in pacman (50%)
- How to change the default operating system in Arch Linux (for UEFI and systemd-boot) (50%)
- WebP image format: converting between formats, WebP lossless and lossy creation and verification in Linux (RANDOM - 50%)