Linux学习8----定时任务
计划任务
定时任务,可以设置固定的时间去执行
默认每分钟检查一次
检查
rpm -qa cron* #定时任务是否安装
systemctl status crond #定时任务是否在运行
systemctl is-active crond #定时任务是否在运行
ps aux|grep crond #查询进行中的定时任务
软件
at
定时任务工具,依赖于atd服务,适用于执行一次就结束的调度任务
crond
需要读取配置文件,有固定的文件格式,通过crontab命令管理文件
-
系统定时任务
/etc/cron.d #系统定时任务目录 /etc/anacrontab #系统定时任务目录 -
用户定时任务
/var/spool/cron/ #用户定时任务目录
语法
[root@centos ~]# cat /etc/crontab
SHELL=/bin/bash
PATH=/sbin:/bin:/usr/sbin:/usr/bin
MAILTO=root
# For details see man 4 crontabs
# 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/文件绝对路径
crontab命令
| 参数 | 含义 | 使用示例 |
|---|---|---|
| -l | list 查看定时任务 | crontab -l |
| -e | edit 编辑定时任务 | crontab -e |
| -i | 删除定时任务,提示用户确认删除,避免出错 | crontab -i |
| -r | 删除定时任务,移除/var/spool/cron/username文件,全没了 | crontab -r |
| -u | 指定用户执行任务,root可以管理普通用户计划任务 | crontab -u root -l |
播种和收获通常不在一个季节,而中间的过程叫做坚持~

浙公网安备 33010602011771号