码迷,mamicode.com
首页 > 其他好文 > 详细

logrotate

时间:2017-05-31 15:27:35      阅读:302      评论:0      收藏:0      [点我收藏+]

标签:linux logrotate

  1. Crontab   命令直接添加

crontab –e

Add below lines to bottom of thefile

0 0-23/3 * * * zip/root2/opt/Avaya/ExperiencePortal/VPMS/SNMP/snmp-agent-daemon.$(date+\%d\%m\%y\%H\%M).zip/root2/opt/Avaya/ExperiencePortal/VPMS/SNMP/snmp-agent-daemon.txt

 

2./etc/crontab文件里添加

[sroot@AAEP7151 etc]# cat/etc/crontab

SHELL=/bin/bash

PATH=/sbin:/bin:/usr/sbin:/usr/bin

MAILTO=root

HOME=/

 

# For details see man 4 crontabs

 

# Example of job definition:

# .---------------- minute (0 -59)

# |  .------------- hour (0 - 23)

# |  | .---------- day of month (1 - 31)

# |  | |  .------- month (1 - 12) ORjan,feb,mar,apr ...

# |  | |  |  .---- day of week (0 - 6) (Sunday=0 or 7) ORsun,mon,tue,wed,thu,fri,sat

# |  | |  |  |

# *  * *  *  * user-name command to be executed

 

* * * * * root run-parts/etc/cron.hourly

 

 

3.利用logrotate机制

/etc/logrotate.conf的内容

在这里定义的优先级最低,如果在别处重新定义,讲覆盖

# rotate log files weekly

weekly

#hourly

 

# keep 4 weeks worth of backlogs

rotate 4

 

# create new (empty) log files afterrotating old ones

create

 

# use date as a suffix of the rotated file

dateext

 

# uncomment this if you want your log filescompressed

#compress

 

# RPM packages drop log rotationinformation into this directory

include /etc/logrotate.d   会去读取已经在/etc/logrotate.d   写好的脚本。

直接在etc/logrotate.conf里面添加要rotate的文件

/var/log/btmp {

   missingok

   monthly

   create 0600 root utmp

   rotate 1

}

/opt/Avaya/ExperiencePortal/VPMS/SNMP/fortest{

      daily

       copytruncate

        rotate 5

       notifempty

       missingok

}

即可

4./etc/logrotate.d里面添加新的脚本

 

[sroot@AAEP7151 etc]# cd /etc/logrotate.d

[sroot@AAEP7151 logrotate.d]# ll

total 48

-rw-r--r--. 1 sroot root  71 Jun 10 2015 cups

-rw-r--r--. 1 sroot root 139 Jun 23  2015 dracut

-rw-r--r--. 1 sroot root 185 Aug 17  2015 httpd

-rw-r--r--. 1 sroot root  88 Nov 24 2016 snmpautorotate

 

[sroot@AAEP7151 logrotate.d]# catsnmpautorotate

/var/log/messages {

daily

copytruncate

rotate 5

size 1k

notifempty

missingok

compress

}

 


logrotate

标签:linux logrotate

原文地址:http://12833256.blog.51cto.com/12823256/1930800

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!