CentOS 自动化任务crontab

centos 自动化任务crontab

ℹ️

本文基于CentOS 7记述。

常用命令

command description
crontab -l 查看当前用户的 crontab 配置
crontab -e 编辑当前用户的 crontab 配置,我用的vim编辑
crontab -u 用户名 -e 为其他用户编辑 crontab配置
crontab -u 用户名 -l 展示其他用户的crontab配置
crontab -r 删除当前用户的 crontab

格式如下

* * * * * 执行命令  
- - - - -  
| | | | |   
| | | | +----- 一周中的哪天 (0 - 7) (Sunday=0 or 7)  
| | | +------- 哪个月 (1 - 12)  
| | +--------- 一月的几号 (1 - 31)  
| +----------- 一天中的第几个小时 (0 - 23)  
+------------- 第几分钟 (0 - 59)

# *代表每一刻都匹配,比如 0 0 * * 0 python ./root/test.py 每周日的0点0时开始执行
# n-md代表范围匹配,比如 0 0 * * 1-5 python ./root/test.py 每周的周一到周五这五天的每天的0点0时开始执行
# /代表间隔匹配,比如 0 6-12/3 * * * python ./root/test.py 每天的6点到12点,每隔3个小时执行一次
posted @ 2024-07-01 15:37  勤匠  阅读(18)  评论(0)    收藏  举报