cron 和anacron 、日志转储的周期任务

[root@localhost ~]# chkconfig --list | grep "cron"
crond 0:off 1:off 2:on 3:on 4:on 5:on 6:off

[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
[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
[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 启动
[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


[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

cron 和anacron 、日志转储的周期任务的更多相关文章
- linux之使用cron,logrotate管理日志文件
1) logrotate配置 logrotate 程序是一个日志文件管理工具.用来把旧的日志文件删除,并创建新的日志文件,我们把它叫做“转储”. 我们可以根据日志文件的大小,也可以根据其天数来 ...
- :Linux 系统日志管理 日志转储
Linux日志服务器设置 使用“@IP:端口”或“@@IP:端口”的格式可以把日志发送到远程主机上. 假设需要管理几十台服务器,每天的重要工作就是查看这些服务器的日志,可是每台服务器单独登录,并且查看 ...
- 详解:(cron , crontab , anacron)
导读: 人类把时间做了切割,想象一条笔直的线永远向前,本来这条直线上什么都没有,但是人类根据时间的长短(单位)在这条直线上做了密密麻麻的标记(世纪-年-月-日-时-分-秒-纳秒......),通过这样 ...
- logrotate日志转储
1 工具目录 ***系统开启selinux,logrotate会不生效*** linux默认会安装logrotate工具,自身的boot.log就是通过它分割转储的. [root@webmaster ...
- nginx 日志 cron任务切割日志
#vim cut_nginx_log.sh #cd /usr/local/nginx/logs/ #/bin/mv access.log access_$(date +%F).log #/usr/lo ...
- logrotate日志管理工具
一.概述 logrotate是一个Linux系统默认安装了的日志文件管理工具,用来把旧文件轮转.压缩.删除,并且创建新的日志文件.我们可以根据日志文件的大小.天数等来转储,便于对日志文件管理. log ...
- [CentOS7] at, bash, cron, anacron
声明:本文主要总结自:鸟哥的Linux私房菜-第十五章.例行性工作排程(crontab),如有侵权,请通知博主 at => /var/spool/at /etc/at.allow, /etc/a ...
- 运维中的日志切割操作梳理(Logrotate/python/shell脚本实现)
对于Linux系统安全来说,日志文件是极其重要的工具.不知为何,我发现很多运维同学的服务器上都运行着一些诸如每天切分Nginx日志之类的CRON脚本,大家似乎遗忘了Logrotate,争相发明自己的轮 ...
- 运维中的日志切割操作梳理(Logrotate/python/shell脚本实现)(转)
对于Linux系统安全来说,日志文件是极其重要的工具.不知为何,我发现很多运维同学的服务器上都运行着一些诸如每天切分Nginx日志之类的CRON脚本,大家似乎遗忘了Logrotate,争相发明自己的轮 ...
随机推荐
- [luogu2216 HAOI2007] 理想的正方形 (2dST表 or 单调队列)
题目描述 有一个ab的整数组成的矩阵,现请你从中找出一个nn的正方形区域,使得该区域所有数中的最大值和最小值的差最小. 输入输出格式 输入格式: 第一行为3个整数,分别表示a,b,n的值 第二行至第a ...
- Flask-SQLAlchemy中解决数据库连接1366报错
报错信息:Warning: (1366, "Incorrect string value: '\\xD6\\xD0\\xB9\\xFA\\xB1\\xEA...' for column 'V ...
- 用Js写贪吃蛇
使用Javascript做贪吃蛇小游戏, 1.自定义地图宽高,蛇的初始速度 2.食物随机出现 3.蛇的样式属性 4.贪吃蛇玩法(吃食物,碰到边界,吃食物后加速,计分,) <!DOCTYPE ht ...
- jQuery选择器练习中,带空格和不带空格的问题
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title> ...
- BLOB的读写操作
//BLOB写入操作package zxt.xsfw.action.ceshi; import javax.servlet.http.HttpServletRequest; import javax. ...
- HDU 4354
思路是在看电视时突然想到的.枚举区间,然后按树形DP来选择最大值看是否满足条件.但枚举区间时的方法低效,看了题解,说枚举区间可以设两个指针逐步移动, 开始 l = r = 1, 记录已经出现的国家. ...
- HDU 2874
简单的tarjan #include <iostream> #include <cstdio> #include <cstring> #include <al ...
- [GraphQL] Apollo React Query Component
In this lesson I refactor a React component that utilizes the graphql higher-order component to the ...
- RDIFramework.NET V2.9版本号 WinFom部分新增与修正的功能
RDIFramework.NET V2.9版本号 WinFom部分新增与修正的功能 转眼间RDIFramework.NET框架走了快6个年头了,随着一个版本号一个版本号的升级改造,如今已经越来越完美 ...
- C++数值类型极限值的获取
C/C++中基本类型的数值极限值一般来说都是与详细平台有关的,在程序设计的过程中为了写出与平台无关的程序则必须通过合理科学的方法去获取各种类型的极值,经常使用的获取方法有两种:一种是传统的C语言所採用 ...