linux计划任务之cron
cron计划任务之用户级
- 1.安装crond
centos7 执行命令:
# yum install -y crontabs
/bin/systemctl restart crond.service #重启服务
/bin/systemctl status crond.service #查看crontab服务状态
- 2.crond进程每分钟会处理一次计划任务 ,存储位置在 /var/spool/cron/
- 3.管理方式
crontab -l 列出当前用户的计划任务
crontab -r 删除当前用户所有的计划任务
crontab -e 编辑当前用户的计划任务
管理员可以使用 -u username,去管理其他用户的计划任务
示例
[root@Server-n93yom ~]# crontab -e //编辑一个计划任务* * * * * date >> /root/tmp/huhu.job 后面的命令可以替换为一个脚本/*.sh
[root@Server-n93yom ~]# crontab -l
* * * * * date >> /root/tmp/huhu.job
[root@Server-n93yom tmp]# tailf huhu.job
Wed Sep 18 23:30:01 CST 2019
[root@Server-n93yom tmp]# crontab -r
[root@Server-n93yom tmp]# crontab -l
no crontab for root
4./etc/cron.deny 中定义的是禁止某用户去执行计划任务
5.语法格式
第一列代表分钟(0-59)
第二列代表小时(0-23)
第三列代表天(1-31)
第四列代表月(1-12)
第五列代表周(0-6) 0表示周日
“*”代表所有的取值范围内的数字。如果直接用“*”则相当于“*/1”
“/”代表每的意思
“*/5″表示每5个单位
“-”代表从某个数字到某个数字
“,”分散的数字
# 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
# | | | | |
# * * * * * command to be executed
cron计划任务之系统级
- 系统计划任务的作用
- 临时文件的清理 /tmp /var/tmp
- 系统信息的采集
- 日志的轮转 (切割)logrotate - cron系统任务文件:/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
\n* * * * * root /etc/cron.hourly/logstash_heartbeat
- 系统任务文件:ls /etc/cron.d/* //crond仅仅会执行每小时定义的脚本 ; /etc/cron.hourly 该文件夹下有个0anacron进程,每小时的01分钟会唤醒anacrond进程
- anacrond详解及命令
[root@Server-n93yom ~]# ls /etc/cron.d/*
/etc/cron.d/0hourly
[root@Server-n93yom ~]# cat /etc/cron.d/0hourly
# Run the hourly jobs
SHELL=/bin/bash
PATH=/sbin:/bin:/usr/sbin:/usr/bin
MAILTO=root
01 * * * * root run-parts /etc/cron.hourly
[root@Server-n93yom ~]# ls /etc/cron.hourly
0anacron logrotate logstash_heartbeat
[root@Server-n93yom ~]# ls /var/spool/anacron/
cron.daily cron.monthly cron.weekly //anacron下的计划任务
[root@Server-n93yom ~]# cat /etc/anacrontab //查询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 //每小时的01分anacron进程会检查每天,每周或者每月的定时任务,若之前因为停机异常等导致的错过的任务,会后续补上
1 5 cron.daily nice run-parts /etc/cron.daily //每天的任务若错过,则会在整点延后五分钟补上上次遗漏的任务
7 25 cron.weekly nice run-parts /etc/cron.weekly //每周的任务若错过,则会在整点延后25分钟补上上次遗漏的任务
@monthly 45 cron.monthly nice run-parts /etc/cron.monthly //每月的任务若错过,则会在整点延后25分钟补上上次遗漏的任务
- cron日志
[root@Server-n93yom ~]# tailf /var/log/cron
Sep 19 23:01:01 Server-n93yom run-parts(/etc/cron.hourly)[1355]: finished 0anacron
Sep 19 23:01:01 Server-n93yom run-parts(/etc/cron.hourly)[1346]: starting logrotate
Sep 19 23:01:02 Server-n93yom run-parts(/etc/cron.hourly)[1362]: finished logrotate
Sep 20 00:01:01 Server-n93yom CROND[5576]: (root) CMD (run-parts /etc/cron.hourly)
Sep 20 00:01:01 Server-n93yom run-parts(/etc/cron.hourly)[5576]: starting 0anacron
Sep 20 00:01:01 Server-n93yom anacron[5585]: Anacron started on 2019-09-20
Sep 20 00:01:01 Server-n93yom anacron[5585]: Normal exit (0 jobs run)
Sep 20 00:01:01 Server-n93yom run-parts(/etc/cron.hourly)[5587]: finished 0anacron
Sep 20 00:01:01 Server-n93yom run-parts(/etc/cron.hourly)[5576]: starting logrotate
Sep 20 00:01:01 Server-n93yom run-parts(/etc/cron.hourly)[5594]: finished logrotate
linux计划任务之cron的更多相关文章
- 《linux 计划任务》- cron
一:什么是计划任务 - 你给手机定了一个闹钟,每天的 7:00 会准时响铃叫你起床,这实际上就是一个计划任务 - 所谓定时任务,就是在已经定好的特定时间去执行的事情. - Cron是一个[守护程序]用 ...
- Linux计划任务入门详解
Linux操作系统定时任务系统 Cron 入门 cron是一个linux下的定时执行工具,可以在无需人工干预的情况下运行作业.由于Cron 是Linux的内置服务,但它不自动起来,可以用以下的方法启动 ...
- Linux计划任务(转载)
Linux计划任务(转载) Linux的计划任务是系统管理方面的一个重要内容,是系统自动完成工作的一种实现方式,正因为有了计划任务,我们才可以完全实现系统管理的脚本化和自动化. 关于计划任务,Linu ...
- Linux 计划任务总结
今天项目用到了,Linux计划任务,从网上找了基本blog看了,总结了下. Linux 下的计划任务有atd和crond两种计划任务.atd服务使用的at命令只能执行一次,而crond服务使用的cro ...
- linux计划任务 学习笔记
原文链接: http://www.tsingfeng.com/?tag=cronjob 本文说的计划任务是指linux的Cronjob.语法 下面是个简单的计划任务: 10 * * * * /usr/ ...
- Linux计划任务,自动删除n天前的旧文件
Linux计划任务,自动删除n天前的旧文件 linux是一个很能自动产生文件的系统,日志.邮件.备份等.虽然现在硬盘廉价,我们可以有很多硬盘空间供这些文件浪费,但需求总是多方面的嘛-我就觉得让系统定时 ...
- Linux计划任务 定时任务 Crond 配置详解 crond计划任务调试 sh -x 详解 JAVA脚本环境变量定义
一.Crond 是什么?(概述) crontab 是一款linux系统中的定时任务软件用于实现无人值守或后台定期执行及循环执行任务的脚本程序,在企业中使用的非常广泛. 现在开始学习linux计 ...
- [转帖]Linux操作系统定时任务系统 Cron 入门0
Linux操作系统定时任务系统 Cron 入门 https://www.cnblogs.com/zhuiluoyu/p/5646400.html cron是一个linux下的定时执行工具,可以在无 ...
- 学习笔记:CentOS7学习之十七: Linux计划任务与日志的管理
目录 学习笔记:CentOS7学习之十七: Linux计划任务与日志的管理 17.1 计划任务-at-cron-计划任务使用方法 17.1.1 at计划任务的使用 17.1.2 查看和删除at将要执行 ...
随机推荐
- ElasticSearch、Kibana 介绍&安装
目录 ElasticSearch 介绍 基于数据库查询的问题 倒排(反向)索引 ES 存储和查询的原理 ES 核心概念 ES 安装 Kibana ElasticSearch 介绍 基于数据库查询的问题 ...
- gitlab修改(重置)root用户密码
gitlab修改(重置)root用户密码 1.使用root权限登录到服务器. 2.使用以下命令启动控制台: gitlab-rails console production 该命令有时候启动比较慢,需 ...
- 面试题68 - II. 二叉树的最近公共祖先
<搜索树结点> <获取路径> 题目描述 给定一个二叉树, 找到该树中两个指定节点的最近公共祖先. 百度百科中最近公共祖先的定义为:"对于有根树 T 的两个结点 p.q ...
- @RestController和@Controller的关系
@RestController注解,相当于@Controller+@ResponseBody两个注解的结合
- VM和CentOS7安装教程
如果图片损坏,点击链接:https://www.toutiao.com/i6491076101664670222/ 安装软件 VMware_workstation_full_12.5.2 CentOS ...
- [转]axios请求超时,设置重新请求的完美解决方法
自从使用Vue2之后,就使用官方推荐的axios的插件来调用API,在使用过程中,如果服务器或者网络不稳定掉包了, 你们该如何处理呢? 下面我给你们分享一下我的经历. 具体原因 最近公司在做一个项目, ...
- Centos7安装erlang以及RabbitMQ Centos启动rabbitmq
本文使用版本: rabbitmq-server-3.8.3-1.el7.noarch.rpm Centos7 erlang 22.3.1 在线安装 yum install esl-erlan ...
- HTML、CSS、Javascript、jQuery、Xml
HTML HTML简介 Hyper Text Markup Language (超文本标记语言)简写:HTML.通过标签来标记要显示的网页中的各个部分.网页文件本身是一种文本文件,通过在文本文件中添加 ...
- Visaul Studio 2015 MFC控件使用之--按钮(Button)
在MFC开发当中,比较常用的控件之一便是Button控件了,该控件的除了可以通过点击产生的开关量当作开关来使用,还可以设置其颜色变化当作显示灯,按钮控件的使用相对来比较简单. 打开工程解决方案的资源视 ...
- 【解决了一个问题】腾讯云中使用ckafka生产消息时出现“kafka server: Message contents does not match its CRC.”错误
初始化的主要代码如下: config := sarama.NewConfig() config.Producer.RequiredAcks = sarama.WaitForAll // Wait fo ...