본문 바로가기
Linux

Logrotate – how to hourly log record on Linux

by 올엠 2020. 10. 22.
반응형

make hourly logrotate

Create an hourly working directory and copy the syslog you will use in the example.

sudo mkdir /etc/logrotate.hourly.d
sudo cp /etc/logrotate.d/syslog /etc/logrotate.hourly.d/syslog

Then type the following:

sudo vi etc/logrotate.hourly.d/syslog

/var/log/syslog
{ 
rotate 48
hourly
missingok
notifempty
delaycompress
compress
postrotate
/usr/lib/rsyslog/rsyslog-rotate
endscript
}

Create sudo vi /etc/logrotate.hourly.conf and include the following to run the /etc/logrotate.hourly.d subtask with:

include /etc/logrotate.hourly.d

Now let cron create a logrotate file(sudo vi /etc/cron.hourly/logrotate) in the hourly directory and run the conf file you just created.

/usr/sbin/logrotate /etc/logrotate.hourly.conf

And with proper permissions to the conf and cron job files, the hourly job is ready to run.

sudo chmod 644 /etc/logrotate.hourly.conf
sudo chmod 755 /etc/cron.hourly/logrotate

Debug/Run immediately

You can check logrotate, but there is a simple way to check it. First, you can check whether it is running through debugging mode.

Debugging mode 

sudo logrotate -d /etc/logrotate.hourly.conf

If you need it right away, you can run it with -f.

Run mode

sudo logrotate -f /etc/logrotate.hourly.conf

Dateformat(legacy version)

Older versions that do not provide the Hourly option can be used with the dateformat option.

dateext
dateformat -%Y%m%d-%s

Add Comment

because parent directory has insecure permissions (It’s world writable or writable by group which is not “root”) Set “su” directive in config file to tell logrotate which user/group should be used for rotation
If you see the above error, you do not have sufficient privileges.
Enter the su root <owning group> in the conf file.
반응형

태그

, , ,

댓글0