区别
Cron: Cron comes from chron, the Greek prefix for ‘time’. Cron is a daemon which runs at the times of system boot.
Crontab: Crontab (CRON TABle) is a file which contains the schedule of cron entries to be run and at specified times. File location varies by operating systems.
- crontab是一个文件(列举了要执行的cron服务的具体内容),也可以指Linux中的crontab 命令。
Cron job or cron schedule: Cron job or cron schedule is a specific set of execution instructions specifying day, time and command to execute. crontab can have multiple execution statements.
crond 系统服务
crond系统服务提供crontab命令来设定cron服务的。
在linux 系统中,由 crond这个系统服务来控制。Linux 系统上面原本就有非常多的计划性工作,因此这个系统服务是默认启动的。
我们可以看下crond这个系统服务的状态:
$ sudo systemctl status cron
● cron.service - Regular background program processing daemon
Loaded: loaded (/lib/systemd/system/cron.service; enabled; vendor preset: enabled)
Active: active (running) since Tue 2022-03-22 16:39:57 UTC; 39s ago
Docs: man:cron(8)
Main PID: 4344 (cron)
Tasks: 1 (limit: 4626)
Memory: 348.0K
CPU: 41ms
CGroup: /system.slice/cron.service
└─4344 /usr/sbin/cron -f -P
Mar 22 16:39:57 esxiubuntu systemd[1]: Started Regular background program processing daemon.
Mar 22 16:39:57 esxiubuntu cron[4344]: (CRON) INFO (pidfile fd = 3)
启动crontab服务
$ systemctl start cron
查看服务是否已经运行用
$ ps -ax | grep cron
设置cron服务的两种方法
- 在命令行中使用
crontab来管理服务(添加/删除相应的任务),该命令其实会将设置的cron服务存储到/var/spool/cron/目录下(以用户名作为子文件夹名称) - 直接编辑
/etc/crontab文件,以添加相应的任务