一、cron是开机自动启动的
[root@localhost ~]# chkconfig --list | grep "cron"
crond 0:off 1:off 2:on 3:on 4:on 5:on 6:off
可以看到 crond 在系统的3级别是自动启动的。3级、5级是常用的级别

[root@localhost ~]# chkconfig --list | grep "cron"
crond 0:off 1:off 2:on 3:on 4:on 5:on 6:off
另外可以在 /etc/init.d 目录中看到自动启动的服务。这些服务可以通过service 来启动和关闭

[root@localhost ~]# cd /etc/init.d
[root@localhost init.d]# ls
abrt-ccpp certmonger halt mcelogd nfs-rdma quota_nld rpcsvcgssd sysstat
abrtd cgconfig ip6tables mdmonitor ntpd rdisc rsyslog udev-post
abrt-oops cgred iptables messagebus ntpdate rdma sandbox winbind
acpid cpuspeed irqbalance netconsole numad restorecond saslauthd ypbind
atd crond kdump netfs oddjobd rngd single
auditd cups killall network portreserve rpcbind smartd
autofs functions lvm2-lvmetad nfs postfix rpcgssd sshd
blk-availability haldaemon lvm2-monitor nfslock psacct rpcidmapd sssd
 
二、cron 开机启动后感什么工作
man cron
Cron should be started from /etc/rc.d/init.d or /etc/init.d (定义cron 开机自启)
 
1、查看 /var/spool/cron
Cron searches /var/spool/cron ,看有没有我们定义的crontab 周期任务
通过crontab -e 创建的周期任务在 此目录显示,同过crond 服务调用
 
 
2-1、查看 /etc/cron.d directory,目录
[root@localhost init.d]# cd /etc/cron.d
[root@localhost cron.d]# ls
0hourly raid-check sysstat
[root@localhost cron.d]# cat 0hourly
SHELL=/bin/bash
PATH=/sbin:/bin:/usr/sbin:/usr/bin
MAILTO=root
HOME=/
01 * * * * root run-parts /etc/cron.hourly
每小时一分 执行 /etc/cron.hourly 目录下的脚本
 
[root@localhost cron.d]# cd  /etc/cron.hourly/
[root@localhost cron.hourly]# ls
0anacron  mcelog.cron
[root@localhost cron.hourly]# cat 0anacron
#!/bin/bash
# Skip excecution unless the date has changed from the previous run
if test -r /var/spool/anacron/cron.daily; then
/var/spool/anacron/cron.daily文件中 存放cron 上次启动时间
如果当期的时间和文件中的时间一致,表示本次已经执行完毕,无需再次执行
day=`cat /var/spool/anacron/cron.daily`
fi
if [ `date +%Y%m%d` = "$day" ]; then
exit 0;
fi # Skip excecution unless AC powered
if test -x /usr/bin/on_ac_power; then
/usr/bin/on_ac_power &> /dev/null
if test $? -eq 1; then
exit 0
fi
fi
/usr/sbin/anacron -s 开机后的第一个 一分钟 (每个小时的第一分钟)开启 anacron 服务
anacron 由 cron 启动
2-2、查看 /etc/anacrontab 中的内容 cat
Cron also searches for /etc/anacrontab
[root@localhost cron]# cat /etc/anacrontab
# /etc/anacrontab: configuration file for anacron
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 随机延迟时间 0-45 分钟
# the jobs will be started during the following hours only
START_HOURS_RANGE=3-22 执行时间 3点到 22点
几天执行一次 固定延迟几分钟 nice 执行的命令
#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
 
分别按 日期 周 月份 执行 /etc/cron.daily /etc/cron.weekly /etc/cron.monthly
目录中的脚本
在这里 看到了 logrotate 日志转储程序,每天执行一次。、
  

[root@localhost cron.daily]# cat logrotate
#!/bin/sh
/usr/sbin/logrotate /etc/logrotate.conf 执行logrotate 转储命令,读
取/etc/logrotate.conf 主要配置文件(包含次要配置文件/etc/logrotate.d)按照 配置文
件的规则对日志进行转储
EXITVALUE=$?
if [ $EXITVALUE != 0 ]; then
/usr/bin/logger -t logrotate "ALERT exited abnormally with [$EXITVALUE]"
fi
exit 0
 
三、日志的转储是通过 anacron 执行的周期任务。是开机后 cron 检查文件和目录后 开启 anacron 服务,在执行 anacron 中定义的周期任务的文件 logrotate 对日志进行转储

cron 和anacron 、日志转储的周期任务的更多相关文章

  1. linux之使用cron,logrotate管理日志文件

    1) logrotate配置   logrotate 程序是一个日志文件管理工具.用来把旧的日志文件删除,并创建新的日志文件,我们把它叫做“转储”.   我们可以根据日志文件的大小,也可以根据其天数来 ...

  2. :Linux 系统日志管理 日志转储

    Linux日志服务器设置 使用“@IP:端口”或“@@IP:端口”的格式可以把日志发送到远程主机上. 假设需要管理几十台服务器,每天的重要工作就是查看这些服务器的日志,可是每台服务器单独登录,并且查看 ...

  3. 详解:(cron , crontab , anacron)

    导读: 人类把时间做了切割,想象一条笔直的线永远向前,本来这条直线上什么都没有,但是人类根据时间的长短(单位)在这条直线上做了密密麻麻的标记(世纪-年-月-日-时-分-秒-纳秒......),通过这样 ...

  4. logrotate日志转储

    1 工具目录 ***系统开启selinux,logrotate会不生效*** linux默认会安装logrotate工具,自身的boot.log就是通过它分割转储的. [root@webmaster ...

  5. nginx 日志 cron任务切割日志

    #vim cut_nginx_log.sh #cd /usr/local/nginx/logs/ #/bin/mv access.log access_$(date +%F).log #/usr/lo ...

  6. logrotate日志管理工具

    一.概述 logrotate是一个Linux系统默认安装了的日志文件管理工具,用来把旧文件轮转.压缩.删除,并且创建新的日志文件.我们可以根据日志文件的大小.天数等来转储,便于对日志文件管理. log ...

  7. [CentOS7] at, bash, cron, anacron

    声明:本文主要总结自:鸟哥的Linux私房菜-第十五章.例行性工作排程(crontab),如有侵权,请通知博主 at => /var/spool/at /etc/at.allow, /etc/a ...

  8. 运维中的日志切割操作梳理(Logrotate/python/shell脚本实现)

    对于Linux系统安全来说,日志文件是极其重要的工具.不知为何,我发现很多运维同学的服务器上都运行着一些诸如每天切分Nginx日志之类的CRON脚本,大家似乎遗忘了Logrotate,争相发明自己的轮 ...

  9. 运维中的日志切割操作梳理(Logrotate/python/shell脚本实现)(转)

    对于Linux系统安全来说,日志文件是极其重要的工具.不知为何,我发现很多运维同学的服务器上都运行着一些诸如每天切分Nginx日志之类的CRON脚本,大家似乎遗忘了Logrotate,争相发明自己的轮 ...

随机推荐

  1. 巴塞尔问题(Basel problem)的多种解法——怎么计算$\frac{1}{1^2}+\frac{1}{2^2}+\frac{1}{3^2}+\cdots$ ?

    (PS:本文会不断更新) $\newcommand\R{\operatorname{Res}}$ 如何计算$\zeta(2)=\frac{1}{1^2}+\frac{1}{2^2}+\frac{1}{ ...

  2. Centos7 下安装 Docker

    一.简介 Docker是一个开源的应用容器引擎:是一个轻量级容器技术:Docker支持将软件编译成一个镜像:然后在镜像中各种软件做好配置,将镜像发布出去,其他使用者可以直接使用这个镜像:运行中的这个镜 ...

  3. 01springMVC入门

    1      MVC模式回顾 Spring MVC是一种基于MVC的Web应用框架. MVC是一种设计模式,MVC在b/s系统下的应用: 执行步骤: 发出请求,请求到MVC当中的C,C接收请求后并不能 ...

  4. apache 与 nginx 详解

    Apache与Nginx的优缺点比较 1.nginx相对于apache的优点: 轻量级,同样起web 服务,比apache 占用更少的内存及资源 抗并发,nginx 处理请求是异步非阻塞的,而apac ...

  5. Mysql 索引-1

    索引的类型 根据数据库的功能,可以在数据库设计器中创建四种索引:唯一索引.非唯一索引.主键索引和聚集索引. 索引的不同应用场景 场景 1. 当数据多且字段值有相同的值得时候用普通索引. 2. 当字段多 ...

  6. C#基础--索引器

    classProgram { staticvoidMain(string[] args) { man mm =new man(); mm[0]="jingya"; mm[1]=&q ...

  7. 洛谷——P1115 最大子段和

    https://www.luogu.org/problem/show?pid=1115#sub 题目描述 给出一段序列,选出其中连续且非空的一段使得这段和最大. 输入输出格式 输入格式: 输入文件ma ...

  8. 嵌入式linux和pc机的linux对照

    linux本身具备的非常大长处就是稳定,内核精悍,执行时须要的资源少.嵌入式linux和普通linux并无本质差别. 在嵌入式系统上执行linux的一个缺点就是其核心架构没有又一次设计过,而是直接从桌 ...

  9. 每一个程序猿都须要了解的一个SQL技巧

    对于数据过滤而言CHECK约束已经算是相当不错了.然而它仍存在一些缺陷,比方说它们是应用到表上面的,但有的时候你可能希望指定一条约束,而它仅仅在特定条件下才生效. 使用SQL标准的WITH CHECK ...

  10. hdoj--1166--敌兵布阵(线段树)

    敌兵布阵 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submi ...