CentOS7设置定时任务每隔30分钟执行一次命令

出处:CentOS 7 设置计划任务 crontabs——https://blog.itnmg.net/2013/05/18/linux-crond

一.安装 crontabs服务并设置开机自启:

  1. yum install crontabs -y  
  2. systemctl enable crond  
  3. systemctl start crond  

二.设置用户自定义定时任务:

  1. vi /etc/crontab  

可以看到:

  1. # Example of job definition:  
  2. #   .  ---------------- 分钟 (0 - 59)  
  3. #   |    .------------- 小时 (0 - 23)  
  4. #   |   |   .---------- 天 (1 - 31)  
  5. #   |   |   |   .------- 月 (1 - 12) OR jan,feb,mar,apr ...  
  6. #   |   |   |   |   .---- 周 (0 - 6) (Sunday=0 or 7) OR sun,mon,tue,wed,thu,fri,sat # | | | | |  
  7. #   *  *   *  *  * user-name command to be executed  

即:

  1. 分钟(0-59) 小时(0-23) 日(1-31) 月(11-12) 星期(0-6,0表示周日) 用户名 要执行的命令  

每隔30分钟root执行一次updatedb命令:

  1. */30 * * * * root updatedb  

每天早上5点定时重启系统:

  1. 0 5 * * * root reboot  

每隔3分钟执行一次/app目录下的python脚本:

  1. */3 * * * * root python3 /app/run.py  

三.保存生效:

  1. #加载任务,使之生效  
  2. crontab /etc/crontab  
  3. #查看任务  
  4. crontab -l  
版权说明: 本文为转载文章,源自互联网,由本站整编
文章分类: 技术教程
字数统计:本文共有 1869 个字
原文地址:

标签:

精彩评论

发表评论: