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

}

 


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章