0

I'm trying to troubleshoot a cron failure on a CentOS 7 VM hosting a website and wiki. There's lot's of fodder on the web about troubleshooting cron, but I am having trouble understanding what I am seeing (and have not found an explanation).

We have cron jobs setup:

# ls -Al /etc/cron.daily/
total 24
-rwxr-x--- 1 root root  332 Nov  4 20:53 yum-daily.cron
-rwxr-x--- 1 root root 1206 Apr 12  2018 gdrive-backup
-rwx------ 1 root root  219 Oct 30 15:12 logrotate
-rwxr-x--- 1 root root  618 Oct 30 10:55 man-db.cron
-rwx------ 1 root root  208 Apr 10  2018 mlocate

But cron does not show any jobs:

[root@ftpit ~]# whoami
root
[root@ftpit ~]# crontab -l
no crontab for root

And:

[root@ftpit ~]# for user in $(cut -f1 -d: /etc/passwd); do crontab -l $user 2>/dev/null; done
[root@ftpit ~]#

cut -f1 -d: /etc/passwd returns a list of users (see below).

Why is cron claiming there are no jobs?


# cut -f1 -d: /etc/passwd
root
bin
daemon
adm
lp
sync
shutdown
halt
mail
operator
games
ftp
nobody
dbus
saslauth
mailnull
smmsp
rpc
sshd
nscd
named
apache
tcpdump
mysql
postfix
<user XXXX>
<user yyyy>
tss
systemd-bus-proxy
systemd-network
ntp
3

The crontab command only manipulates the spools in /var/spool/cron, it doesn’t take jobs defined in /etc/cron.daily etc. into account.

There’s no nice way of listing all cron jobs; the following will give some idea:

head -n -0 /var/spool/cron/* /etc/crontab /etc/cron.d/*
ls /etc/cron.{hourly,daily,weekly,monthly}/

(Showing all the crontabs might include false-positives for files corresponding to removed users.)

With systemd you might also want to list the timers:

systemctl list-timers

When debugging cron jobs, it’s worth bearing in mind that on many systems, daily, weekly, and monthly jobs are run by anacron, not cron.

See also How can get a list of all scheduled cron jobs on my machine?

  • 1
    Yes, on SO, it’s often the case that the first apparently sensible answer wins... – Stephen Kitt Dec 20 '18 at 15:52
  • 1
    systemd can run cron jobs, with systemd-cron (which isn’t part of systemd, or even used anywhere by default AFAIK); on CentOS cron jobs are still run by Cronie. – Stephen Kitt Dec 20 '18 at 16:28
  • This may have something to do with the failures: OpenVZ, CentOS SCL and failed cron jobs? – user56041 Dec 20 '18 at 16:42
  • I don’t think OpenVZ would change anything, and I doubt SCL would break cron... – Stephen Kitt Dec 20 '18 at 16:58

Your Answer

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