1. crond计划任务概述
什么是计划任务,计划任务类似于我们平时生活中的闹钟。
在Linux
系统的计划任务服务crond
可以满足周期性执行任务的需求。
crond
进程每分钟会处理一次计划任务, 计划任务主要是做一些周期性的任务目前最主要的用途是定时备份数据
Schedule one-time tasks with at. 一次性调度执行 at
Schedule recurring jobs with cron. 循环调度执行 cron
Schedule recurring system jobs. 所有计划任务执行中的输出都会以邮件的方式发送给指定用户, 除非重定向
循环调度执行cron 进程每分钟会处理一次计划任务
[root@wenhs5479 ~]# systemctl status crond.service
● crond.service - Command Scheduler
Loaded: loaded (/usr/lib/systemd/system/crond.service; enabled; vendor preset: enabled)
Active: active (running) since 日 2019-03-24 19:26:36 CST; 3min 22s ago
Main PID: 9443 (crond)
CGroup: /system.slice/crond.service
└─9443 /usr/sbin/crond -n
3月 24 19:26:36 wenhs5479 systemd[1]: Started Command Scheduler.
3月 24 19:26:36 wenhs5479 crond[9443]: (CRON) INFO (RANDOM_DEL...
3月 24 19:26:37 wenhs5479 crond[9443]: (CRON) INFO (running wi...
Hint: Some lines were ellipsized, use -l to show in full.
[root@wenhs5479 ~]# ps aux |grep crond
root 9443 0.4 0.0 126284 1716 ? Ss 19:26 0:01 /usr/sbin/crond -n
root 11960 0.0 0.0 112728 988 pts/0 S+ 19:30 0:00 grep --color=auto crond
[root@wenhs5479 ~]#
计划任务分为以下两种情况:
- 系统级别的定时任务:
清理系统缓存
临时文件清理
系统信息采集
日志文件切割
- 用户级别的定时任务:
定时同步互联网时间
定时备份系统配置文件
定时备份数据库文件
2. crond配置文件详解
文件 说明
/etc/crontab //crontab配置文件
/etc/cron.deny //该文件中所列用