➜ ~ 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.
# Edit this file to introduce tasks to be run by cron. # # Each task to run has to be defined through a single line # indicating with different fields when the task will be run # and what command to run for the task # # To define the time you can provide concrete values for # minute (m), hour (h), day of month (dom), month (mon), # and day of week (dow) or use '*' in these fields (for 'any'). # # Notice that tasks will be started based on the cron's system # daemon's notion of time and timezones. # # Output of the crontab jobs (including errors) is sent through # email to the user the crontab file belongs to (unless redirected). # # For example, you can run a backup of all your user accounts # at 5 a.m every week with: # 0 5 * * 1 tar -zcf /var/backups/home.tgz /home/ # # For more information see the manual pages of crontab(5) and cron(8) # # m h dom mon dow command 1 1 1 * * shutdown -r now # 每月1号1点1分重启系统
查看定时任务
1
crontab -l
删除定时任务
1
crontab -r
cron
cron 是 crontab 命令的守护进程,在后台运行,负责每分钟监测是否有预定的任务需要执行。
查看 cron 守护进程是否运行
1 2 3 4 5 6 7 8 9 10 11 12 13
➜ ~ systemctl status cron.service ● cron.service - Regular background program processing daemon Loaded: loaded (/lib/systemd/system/cron.service; enabled; vendor preset: enabled) Active: active (running) since Wed 2021-03-17 17:10:58 CST; 1 day 19h ago Docs: man:cron(8) Main PID: 417 (cron) Tasks: 1 (limit: 1160) Memory: 6.8M CGroup: /system.slice/cron.service └─417 /usr/sbin/cron -f
Warning: some journal files were not opened due to insufficient permissions.