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将要执行 ...
随机推荐
- Java初学者作业——使用eclipse简单的输出(打印)游戏菜单
返回本章节 返回作业目录 需求说明: 使用eclipse创建Java项目,在Java程序中输出游戏菜单. 为 Java 程序添加单行和多行注释. 实现思路: 在 eclipse 中创建项目及Java类 ...
- 【MySQL作业】sum、max 和 min 聚合函数——美和易思聚合函数应用习题
点击打开所使用到的数据库>>> 1.统计商品最高单价和最低单价. -- 获取所有商品的最高单价和最低单价: select max(unitPrice) 最高单价 , min(unit ...
- Eclipse导入Zookeeper源码Version2017.11.3
将Zookeeper源码导入Eclipse, Zookeeper源码需要使用ant构建后才能导入Eclipse, 和Solr的源码一样也是使用ant构建的, 大部分可以参考Eclipse导入Solr源 ...
- 2021 编程语言排行榜出炉!C#年度语言奖
IEEE Spectrum 发布了 2021 年度编程语言排行榜,其中 Python 在总榜单以及其他几个分榜单中依然牢牢占据第一名的位置.另外值得关注的是微软 C# 语言,它的排行从 2020 年的 ...
- Python DataFrame to_sql方法插入日期或时间类型的数据时 报ORA-01861 文字与字符串不匹配 的解决方法
业务团队近期提出一个需求: 希望在接口调用之前先批量插入Excel中的数据作为数据预置 这个需求以前已经开发完成 本来以为可以很快调试完毕 没成想遭遇一个难关 DataFrame.to_sql方法在执 ...
- 初识python: 继承实例 - 学校、老师、学生
对学校.老师.学生做一个分类,并抽象成类.并实现各自的一些功能.代码如下: 父类1:学校 # 学校 class School(object): def __init__(self,name,addr) ...
- Linux设置新的服务器登录端口
root用户登录服务器 22端口修改为22525,22端口也打开,以防新端口设置有问题,登录不上服务器 向防火墙中添加修改的端口 systemctl start firewalld firewall- ...
- linux 设置root 密码
指令意思: sudo -i 是 切换到root权限 ,如果没有密码,则直接可以操作,有密码则会要求输入密码 sudo passwd root 是修改密码指令 ,回车后 提示输入新密码 新密码需要输 ...
- centos7 alias别名永久生效
进入/etc/profile.d/目录 cd /etc/profile.d/ 在profile.d目录随意创建一个sh文件,例如alias_test.sh vi alias_test.sh##里面的内 ...
- webpack 多环境打包
目前来说有两种方案: 方案一: 1.修改build文件夹下build.js文件 添加声明变量 2.修改config文件夹下dev.env.js文件 这个是开发环境所用版本 3.修改config文件夹下 ...