50

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.

80

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

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)
  • Note: this works for sh but not bash. – Tiw Jul 16 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
  • 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

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.