0

I thought I understood cron but it appears that I don't.

I am using cron on Red Hat Enterprise Linux v. 4

We organize cron jobs by storing them in /etc/cron.d. They are all owned by root. (have root in the cron spec in the .cron file)

When stored there, if coded correctly, the jobs run.

However, even though logged in as root

crontab -l

does not list the jobs in /etc/cron.d, even though they are actually running.

What am I not understanding? Every web search I've done on this tells me that crontab -l is the command to run. Yet it doesn't list all the jobs it's running.

UPDATE: Since it wasn't clear, my question is really

What command lets you see all the cron jobs that are scheduled to run for a given user?

You can find many sources that say crontab -l is that command, but that is demonstrably not so.

2

As stated in the manual

crontab -l

lists the crontab for the current user

/var/spool/cron/root

if you happen to be root.

crontab -u other -l

for some other user. Edit the crontab with

crontab -e

Format is

#.---------------- minute (0 - 59)
#|      .------------- hour (0 - 23)
#|      |       .---------- day of month (1 - 31)
#|      |       |       .------- month (1 - 12) OR jan,feb,mar,apr ...
#|      |       |       |       .---- day of week (0 - 6) (Sunday=0 or 7)  OR sun,mon,tue,wed,thu,fri,sat
#|      |       |       |       |
#*      *       *       *       *       the command to be executed

0       */2     *       *       *       /every2h.sh

In addition to that there is also

find  /etc/cron* -type f

which is not advisable to use as it's meant for distribution cron jobs. all of those files run as root and are not writable by other users by default.

  • Well and good but that doesn't answer the question "what is the command that shows all cron jobs that are scheduled to run"? crontab -l "lists the crontab for the current user" but that is not a list of all jobs that are scheduled to run for that user. – Steve Cohen Oct 6 '16 at 18:14
  • Yes, thanks, your update is a more correct version of the answer that I myself gave. – Steve Cohen Oct 6 '16 at 21:01
0

According to man crontab, there is -u option to append a username.

To show scheduled jobs for a user, usage is:

crontab -l -u username

And you need to have super user privileges to user it. If you are not the root user, then use it as:

sudo crontab -l -u username

And, according to man crond and /etc/crontab, there is no command to show the users owning the jobs. The owners of the jobs are saved in the files with this structure:

# Example of job definition:
# .---------------- minute (0 - 59)
# |  .------------- hour (0 - 23)
# |  |  .---------- day of month (1 - 31)
# |  |  |  .------- month (1 - 12) OR jan,feb,mar,apr ...
# |  |  |  |  .---- day of week (0 - 6) (Sunday=0 or 7) OR sun,mon,tue,wed,thu,fri,sat
# |  |  |  |  |
# *  *  *  *  * user-name  command to be executed

Thus, I think you will have to look for usernames in each file or write a bash script to select and list them.

Also, check this question: What's the difference between /etc/cron.d and /var/spool/cron?

  • That doesn't help either. The basic problem is that there are two systems, the crontab system and the /etc/cron.d system. There doesn't seem to be anything that shows both a single schedule for both systems. – Steve Cohen Oct 6 '16 at 20:36
  • Updated answer. – ukll Oct 6 '16 at 21:14
-1

cat /etc/cron.d/* seems to show the same type of listing for those items deployed there as crontab -l displays for those items deployed through crontab.

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.