67

I have a script being run automatically that I can't find in the crontab for the expected users, so I'd like to search all users' crontabs for it.

Essentially I want to run a crontab -l for all users.

106

Well depends on the script but easily you can find your crontab as root with

crontab -l -u <user>

Or you can find crontab from spool where is located file for all users

cat /var/spool/cron/crontabs/<user>

To show all users' crontabs with the username printed at the beginning of each line:

cd /var/spool/cron/crontabs/ && grep . *
| improve this answer | |
  • 1
    Awesome, looking in /var/spool/cron/crontabs/ worked nicely, thanks! – Highly Irregular Mar 13 '14 at 22:04
  • 2
    crontab -e -u <user> to edit it works as well – vladkras Aug 4 '17 at 11:24
  • 1
    /var/spool/cron/<user> on my Centos 7 host. – Bob Stein Sep 3 '19 at 18:49
12

One liner which lists all users and prints cron for every user:

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

This solution:

  • Doesn't require knowing a system specific crontab path (e.g. /var/spool/cron/crontabs/ vs /var/spool/cron/
  • Won't list "orphan" crons, i.e. crons for users that don't exist anymore (and thus are not executed effectively)
| improve this answer | |
  • Note: this works for sh but not bash. – Tiw Jul 16 '19 at 7:15
0

In RHEL/OEL you can list the cron jobs created by all users:

#cd /var/spool/cron/
#ls -1
root
oracle
user1

To see root's cronjobs:

#cat root
| improve this answer | |
  • The crontab(1) interface (command) should be used, as it protects against concurrent editing of the crontab database. – Dirk Jan 10 '18 at 0:07
0

Using the following command, we findall Cron jobs, on the specified system.

find /etc/cron* -type f -perm -o+w -exec ls -l {} \;
| improve this answer | |
0
for USER in `cat /etc/passwd | awk -F ":" '{print $1}'`
do
  echo "this crontab for user : $USER"
  crontab -u $USER -l 2>&1
done >> list_all_cron

Strange need to escape chars on this web site. I think copy paste won't work

Well you got the point : loop all users from /etc/passwd + awk and ask for crontab with crontab -u -l

| improve this answer | |
  • Welcome to the site, and thank you for your contribution. Indeed the backtick is used for in-line comment formatting, making it difficult to use. Still, please note that the backtick format is deprecated anyway for command substitutions, and the $( ... ) format should be used instead. Also, you don't really need to cat a file into awk, just give the file to be read as parameter after the command. – AdminBee Jun 4 at 11:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.