crond定时任务


centos # 重启服务
service crond restart
-----------------------------------------
chkconfig crond on
systemctl list-unit-files crond on
# 查询,提示被覆盖
chkconfig --list | grep cron
------------------------------------------
systemctl list-unit-files | grep cron
crond.service enabled
------------------------------------------

vi /etc/cron.
cron.d/ cron.daily/ cron.deny cron.hourly/ cron.monthly/ cron.weekly/

crontab 【选项】
-e: 编辑crontab 定时任务
-l: 查询crontab 任务
-r:删除当前用户所有crontab任务 注意: crontab 是当前用户的,只有当前用户的权限,crontab 会绑定 user 的身份

crontab -e
会进入一个当前用户的文件,在这个文件下编写任务 编写任务格式 """
* * * * * 执行任务
第一个* 一小时当中的第几分钟0-59
第二个* 一天当中的第几个小时 0-23
第三个* 一月当中的第几天 1-13
第四个* 一年当中的第几个月 1-12
第五个* 一周当中的第几个星期 0-7 0,7都代表周日
""" 例如
***********************************
10 * * * * /root/nginx_start.sh
会在1点10分,2点10,一小时执行一次
************************************ ************************************
如果想每隔10分钟执行一次
*/10 * * * * * /pwd/脚本
*代表任意时间,每隔十分钟执行一次
************************************ +++++++++++++++++++++++++++++++++++++++
* * * * * 这个是每分钟执行一次
,代表不连续时间 0 8,12,16 * * *
每天8点整 12点整 16点整 都执行一次
+++++++++++++++++++++++++++++++++++++++ +++++++++++++++++++++++++++++++++++++++
-代表连续的时间
0 5 * * 1-6
周1到周6的早上5点整执行
+++++++++++++++++++++++++++++++++++++++ +++++++++++++++++++++++++++++++++++++++
45 22 * * * 每天22点45分
0 17 * * 1 每周1的17点整
0 5 1,15 * * 每月1号和5号 的 5点整
40 4 * * 1-5 周1到周5的4点40分
*/10 4 * * * 4点 4点10分 4点20分 ...4点50分 1小时执行6次
0 0 1,5 * 1 每周1 或1号 或 5号 的凌晨
+++++++++++++++++++++++++++++++++++++++ """
注意事项 星期和几号 不要同时出现,自己容易混乱 最小时间范围是分钟
最大时间范围是月
超出范围都不能实现 六个选项不能为空 脚本执行尽量使用绝对路径
系统的path环境变量,和我们用户的环境变量并不完全一致
""'

系统的 crontab,使用配置文件编写定时任务


crontab -e 是把定时任务绑定到当前用户上的 # 使用配置文件编写定时任务
/etc/crontab 这个是配置文件

vi /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 user-name 指定执行用户名
command to be executed 执行的命令或者脚本 ********************************************************
第二种方法
将脚本放入
/etc/cron.{daily,weekly,monthly}
目录下,会自动每天 每周 每月 执行一次
********************************************************

"""
定时任务 尽量把时间错开
"""

anacron定时任务


这个任务的好处是
如果我定在5点执行一个任务
但是我4点50-5点10分关机了 当我5点10分开机后,anacron 会检测有没有漏掉的定时任务,会重新执行
它只会检测目录下的执行任务 ,crontab -e 的不会检测 anacron 检测周期
vi /var/spool/anacron/ 目录记录的是上一次执行时间
下一次执行 会和上一次进行比较 anacron 检测时间比较粗略 vi /etc/anacrontab “”“
# /etc/anacrontab: configuration file for anacron # See anacron(8) and anacrontab(5) for details. SHELL=/bin/sh
PATH=/sbin:/bin:/usr/sbin:/usr/bin
MAILTO=root
# the maximal random delay added to the base delay of the jobs
RANDOM_DELAY=45 # 随机延迟时间,错峰执行
# the jobs will be started during the following hours only
START_HOURS_RANGE=3-22 #period in days delay in minutes job-identifier command
1 5 cron.daily nice run-parts /etc/cron.daily
7 25 cron.weekly nice run-parts /etc/cron.weekly
@monthly 45 cron.monthly nice run-parts /etc/cron.monthly
”“”

来源:https://blog.csdn.net/sunt2018/article/details/86499396

最新文章

  1. fir.im Weekly - 聊聊 Google 开发者大会
  2. 图片处理GraphicsMagick & ImageMagick
  3. TMethod
  4. webService发布和调用--Axis2
  5. SwipeRefreshLayout实现上拉加载
  6. Windows窗体应用程序(非Console)使用libuv实现简单的异步WEB服务器
  7. jsp与El,jstl知识点总结归纳
  8. 菜鸟从零学编程(八)——将MyEclipse项目导入到Eclipse
  9. mysql repair data 语句
  10. python制作安装包(setup.py)
  11. ubuntu12中设置PATH环境变量的几种方法(三种办法)
  12. 设计模式总结5--命令模式 commend pattern
  13. 面向对象设计模式_生成器模式详解(Builder Pattern)
  14. QTableView
  15. MyIbatis和Hibernate的区别--2019-04-26
  16. LNMP平台搭建之一:nginx编译安装
  17. Android中的透明度
  18. MyBatis 作用域(Scope)和生命周期
  19. FPGA基础之逻辑单元(LE or LC)的基本结构
  20. PHP几种加密方式

热门文章

  1. Redis主从复制(读写分离)
  2. docker-compose 官网下载特别慢怎么办?
  3. [CSP-S2019]划分 题解
  4. 洛谷 P4995 跳跳!
  5. 返回boolean的mybatis查询
  6. 高德地图POI爬取_Python
  7. 矩阵LU分解的MATLAB与C++实现
  8. Webpack 打包优化之体积篇
  9. 转发请求RequestDispatcher()方法用于与页面的交互
  10. 【NOIP2013模拟】七夕祭