在 Fexora Server 32 上,使用 systemctl list-timers --all 不會顯示新的 cron 作業

在 Fexora Server 32 上,使用 systemctl list-timers --all 不會顯示新的 cron 作業

我剛剛將一台新伺服器上線並按照舊伺服器有關 cron 的方式對其進行配置,但作業並未運行。因此,我仔細檢查了配置並檢查了當前 cron 是否與舊的 cron 一樣工作。是的,看來是這樣!

由於它是一個“systemd”類型的系統,我運行了適當的命令來查看它認為已安排的內容,這就是我得到的:

# 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.

這一切都很好,但它沒有顯示我的具體添加內容 - 其中任何一個。所以,我做了我認為正確的事情,我運行systemctl reload crond.service並得到了相同的輸出。所以我重新啟動,仍然得到相同的輸出!

我的補充是:

  1. cron.d:本地 - 一組不在通常時間表上的本地事物
  2. cron.daily:backup.daily logrotate mail_check
  3. cron.每月;每月備份,以及;
  4. cron.每週;每週備份

我完全準備好相信我在配置中做錯了什麼,或者可能還有其他一些問題,為什麼我不認為它們運行了,但它們運行了。但我沒有看到systemctl list-timers 輸出中的其他條目,這些條目是在我開始使用自己的添加內容之前就已安裝的軟體包放置在那裡的。

也許問題是我不熟悉列表計時器輸出?難道它不應該也顯示其他這些工作嗎?

答案1

就像 Linux 中的許多事情一樣,做事情的方法不只一種。 Cron 和 systemd 定時器是做類似 cron 的事情的不同方式,就像 upstart 一樣,init.d 和 systemd 是 3 個不同的 init 系統。

許多 cron 作業都屬於特定用戶,因此您可以crontab -l作為特定用戶,或crontab -u username -l以 root 身分檢查另一個使用者的 cron 作業。

你還有每日、每週、每月等等

雖然您可以深入研究每個文件,但它們是一系列文件,因此

所以ls -la /etc/cron.*會給你一個概述

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

將這些轉換為systemd 定時器腳本超出了這個答案的範圍,但它們是不是與經典的 cron 作業相同。

相關內容