0

I've just brought a new server online and configured it the way the old one was regarding cron, but the jobs aren't running. So, I went through the configuration carefully and checked that the current cron works the way the old one did. Yes, it appears so!

As it's a "systemd" type system, I ran the appropriate command to see what it thinks is scheduled, and here's what I got:

# systemctl list-timers --all
NEXT                        LEFT          LAST                        PASSED     UNIT                         ACTIVATES
Sun 2020-08-16 15:15:55 PDT 5min left     Sun 2020-08-16 14:15:54 PDT 54min ago  dnf-makecache.timer          dnf-makecache.service
Sun 2020-08-16 20:57:26 PDT 5h 47min left Sat 2020-08-15 20:57:26 PDT 18h ago    systemd-tmpfiles-clean.timer systemd-tmpfiles-clean.service
Mon 2020-08-17 00:00:00 PDT 8h left       Mon 2020-08-10 00:00:00 PDT 6 days ago fstrim.timer                 fstrim.service
Mon 2020-08-17 00:00:00 PDT 8h left       Sun 2020-08-16 00:00:01 PDT 15h ago    mlocate-updatedb.timer       mlocate-updatedb.service
Mon 2020-08-17 00:00:00 PDT 8h left       Sun 2020-08-16 00:00:01 PDT 15h ago    unbound-anchor.timer         unbound-anchor.service

5 timers listed.

That's all well and good, but it's not showing my specific additions - any of them. So, I did what I thought was correct, I ran systemctl reload crond.service and got the same output. So I restarted and still got the same output!

My additions are:

  1. cron.d: local - a set of local things that aren't on the usual schedules
  2. cron.daily: backup.daily logrotate mailbox_check
  3. cron.monthly; backup.monthly, and;
  4. cron.weekly; backup.weekly

I'm fully prepared to believe I did something wrong in the config, or maybe there's some other issue on why I don't THINK they ran but they did. But I'm not seeing the other entries in the systemctl list-timers output that were put there by installed packages that were there before I even started mucking with my own additions.

Perhaps the problem is my unfamiliarity with the list-timer output? Is it not supposed to show these other jobs, too?

Richard T
  • 1,206
  • 12
  • 29
  • Cron jobs do not show up there! – Michael Hampton Aug 16 '20 at 22:44
  • @MichaelHampton AH! Then that command doesn't do what I thought it did! ... Is there a way to show what WILL happen? You know, walk the config and tell us what the future looks like as presently configured? That would be a very useful tool! – Richard T Aug 16 '20 at 22:53
  • @MichaelHampton BTW, what DOES that command do?! I thought it showed us cron jobs... – Richard T Aug 16 '20 at 22:54
  • Cron is old school, and if you want to know what it's going to do, you look at all your crontab files. Now, you could write _new_ systemd timers of your own to _replace_ your cron jobs, but this is up to you. – Michael Hampton Aug 16 '20 at 22:56
  • @MichaelHampton ...I think my question is a fair one that will help others someday, so why not give us an answer like that, I'll mark it as the answer, and if you can, while you're at it, point is in the general direction of how to set up systemd timers, that'd be grand. – Richard T Aug 16 '20 at 22:58

1 Answers1

1

As with many things in linux, there's more than one way to do things. Cron and systemd timer are different ways to do cron-like thing, much like upstart, init.d and systemd are 3 different init systems.

Many cron jobs are owned by a specific user, so you can either crontab -l as the specific user, or crontab -u username -l to check the cron jobs of another user as root.

You also have daily, weekly monthly and so on

While you can dig into each, they're a series of files so

so ls -la /etc/cron.* would give you an overview

geek@heckate_router:~$ ls -la /etc/cron.*
/etc/cron.d:
total 28
drwxr-xr-x   2 root root  4096 Jan 22  2020 .
drwxr-xr-x 117 root root 12288 Aug 12 06:54 ..
-rw-r--r--   1 root root   589 Jun 26  2018 mdadm
-rw-r--r--   1 root root   102 Nov 16  2017 .placeholder
-rw-r--r--   1 root root   190 Jul 25  2018 popularity-contest

/etc/cron.daily:
total 76
drwxr-xr-x   2 root root  4096 Aug 12 06:54 .
drwxr-xr-x 117 root root 12288 Aug 12 06:54 ..
-rwxr-xr-x   1 root root   376 Nov 20  2017 apport

.....


/etc/cron.hourly:
total 20
drwxr-xr-x   2 root root  4096 Jul 25  2018 .
drwxr-xr-x 117 root root 12288 Aug 12 06:54 ..
-rw-r--r--   1 root root   102 Nov 16  2017 .placeholder

/etc/cron.monthly:
total 20
drwxr-xr-x   2 root root  4096 Nov 18  2018 .
drwxr-xr-x 117 root root 12288 Aug 12 06:54 ..
-rw-r--r--   1 root root   102 Nov 16  2017 .placeholder

/etc/cron.weekly:
total 28
drwxr-xr-x   2 root root  4096 May 30  2019 .
drwxr-xr-x 117 root root 12288 Aug 12 06:54 ..
-rwxr-xr-x   1 root root   723 Apr  7  2018 man-db
-rw-r--r--   1 root root   102 Nov 16  2017 .placeholder
-rwxr-xr-x   1 root root   211 Jun 27  2018 update-notifier-common

Converting these to systemd timer scripts is outside the scope of this answer but they are not the same as a classic cron job.

Journeyman Geek
  • 6,977
  • 3
  • 32
  • 50