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

1 Answers1

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?

Stephen Kitt
  • 434,908