CentOS7定时任务:crontab

1 查看定时任务

1.0 方式1

crontab -l

1.2 方式2

  • 直接进入定时任务文件
vim /etc/crontab
  • 文件内容

CentOS7定时任务:crontab_第1张图片

图 定时任务

2 配置定时任务

2.1 参数

crontab共有5个时间参数,格式为:

minute hour day month week user-name command
序号 参数 描述
1 minute 分钟(0-59)
2 hour 小时(0-23)
3 day 天(0-31)
4 month 月(0-11)
5 week 周(0-6),即周日~周六
6 user-name 用户名,如root
7 command 指定的命令

2.2 添加定时任务

  • 输出日志到指定文件:
    日志持续填充:>>(新日志在旧日志后面添加)
* * * * * root python /home/xindaqi/python/test.py >> /home/xindaqi/logs/log.txt 2>&1 &
  • 日志覆盖:>(新日志覆盖旧日志)
* * * * * root python /home/xindaqi/python/test.py > /home/xindaqi/logs/log.txt 2>&1 &

2.3 使用

序号 定时任务 描述
1 * * * * * root python /home/xindaqi/test.py 每分钟执行一次
2 0 8,18 * * * root python /home/xindaqi/test.py 每天8点和18点执行
3 更新ing 更新ing

你可能感兴趣的:(#,CentOS7,CentOS,定时任务,crontab)