ยง2024-11-04

  1. install
$ sudo apt install cron
$ systemctl status cron.service 
โ— cron.service - Regular background program processing daemon
     Loaded: loaded (/usr/lib/systemd/system/cron.service; enabled; preset: enabled)
     Active: active (running) since Sat 2024-11-02 09:27:38 CST; 2 days ago
       Docs: man:cron(8)
   Main PID: 1288 (cron)
      Tasks: 1 (limit: 3346)
     Memory: 524.0K (peak: 2.7M)
        CPU: 7.044s
     CGroup: /system.slice/cron.service
             โ””โ”€1288 /usr/sbin/cron -f -P
....
# /usr/lib/systemd/system/cron.service
[Unit]
Description=Regular background program processing daemon
Documentation=man:cron(8)
After=remote-fs.target nss-user-lookup.target

[Service]
EnvironmentFile=-/etc/default/cron
ExecStart=/usr/sbin/cron -f -P $EXTRA_OPTS
IgnoreSIGPIPE=false
KillMode=process
Restart=on-failure
SyslogFacility=cron

[Install]
WantedBy=multi-user.target
alexlai@hc4Noble:~$ grep CRON /var/log/syslog
2024-11-03T00:05:01.208789+08:00 hc4Noble CRON[22559]: (root) CMD (command -v debian-sa1 > /dev/null && debian-sa1 1 1)
2024-11-03T00:15:01.223683+08:00 hc4Noble CRON[22584]: (root) CMD (command -v debian-sa1 > /dev/null && debian-sa1 1 1)
2024-11-03T00:17:01.245042+08:00 hc4Noble CRON[22589]: (root) CMD (cd / && run-parts --report /etc/cron.hourly)
2024-11-03T00:25:01.265476+08:00 hc4Noble CRON[22599]: (root) CMD (command -v debian-sa1 > /dev/null && debian-sa1 1 1)
2024-11-03T00:35:01.280804+08:00 hc4Noble CRON[22612]: (root) CMD (command -v debian-sa1 > /dev/null && debian-sa1 1 1)
2024-11-03T00:45:01.304986+08:00 hc4Noble CRON[22627]: (root) CMD (command -v debian-sa1 > /dev/null && debian-sa1 1 1)
2024-11-03T00:55:01.320597+08:00 hc4Noble CRON[22648]: (root) CMD (command -v debian-sa1 > /dev/null && debian-sa1 1 1)
2024-11-03T01:05:01.340538+08:00 hc4Noble CRON[22659]: (root) CMD (command -v debian-sa1 > /dev/null && debian-sa1 1 1)
2024-11-03T01:15:01.360385+08:00 hc4Noble CRON[22672]: (root) CMD (command -v
...

$ cat /etc/crontab 
# /etc/crontab: system-wide crontab
# Unlike any other crontab you don't have to run the `crontab'
# command to install the new version when you edit this file
# and files in /etc/cron.d. These files also have username fields,
# that none of the other crontabs do.

SHELL=/bin/sh
# You can also override PATH, but by default, newer versions inherit it from the environment
#PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin

# 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
17 *	* * *	root	cd / && run-parts --report /etc/cron.hourly
25 6	* * *	root	test -x /usr/sbin/anacron || { cd / && run-parts --report /etc/cron.daily; }
47 6	* * 7	root	test -x /usr/sbin/anacron || { cd / && run-parts --report /etc/cron.weekly; }
52 6	1 * *	root	test -x /usr/sbin/anacron || { cd / && run-parts --report /etc/cron.monthly; }
#