• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar
  • Skip to footer navigation

The Geek Diary

  • OS
    • Linux
    • CentOS/RHEL
    • Solaris
    • Oracle Linux
    • VCS
  • Interview Questions
  • Database
    • oracle
    • oracle 12c
    • ASM
    • mysql
    • MariaDB
  • DevOps
    • Docker
    • Shell Scripting
  • Big Data
    • Hadoop
    • Cloudera
    • Hortonworks HDP

How to Create a Custom Log File Rotation by logrotate in Linux

by admin

In this example case /var/log/secure.log will be rotated daily and if the log file size exceeds 100mb rotate process will start.

1. By default system rotates all major OS logs by checking syslog file located in /etc/logrotate.d/

# cat /etc/logrotate.d/syslog
/var/log/cron
/var/log/maillog
/var/log/messages
/var/log/secure
/var/log/spooler
{
sharedscripts
postrotate
/bin/kill -HUP 'cat /var/run/syslogd.pid 2> /dev/null' 2> /dev/null || true
endscript
}
#

2. To add separate log rotation policy for /var/log/secure simply hash the entry in above syslog file and create separate file in /etc/logrotate.d/

# cd /etc/logrotate.d/
# touch securelog
# chmod 644 securelog; chown root:root securelog
# vi securelog

/var/log/secure.log
{
daily
maxsize 100M
rotate 4
}

Explanatiion

daily – rotate log file daily.
maxsize – Log files are rotated when they grow bigger than X size bytes even before the additionally specified time interval (daily, weekly, monthly, or yearly).
rotate – Log files are rotated [count] times before being removed or mailed to the address specified in a mail directive. If count is 0, old versions are removed rather then rotated.

Check manual page (man logrotate) for more information.

# man logrotate

Filed Under: CentOS/RHEL 5, CentOS/RHEL 6, Linux

Some more articles you might also be interested in …

  1. How To Retain Current And Older Linux Packages While Doing Update With ‘yum’ Command
  2. How To Setup UDEV Rules For RAC OCR And Voting Devices on Partitions
  3. “No space left on device” – kdump generation issue (CentOS/RHEL)
  4. hashcat Command Examples in Linux
  5. grub-mkconfig Command Options
  6. How to Find Number of CPU Sockets on a CentOS/RHEL System
  7. ac Command Examples in Linux
  8. Apache HTTP server – most commonly used containers (special configuration directives)
  9. “device-mapper: resume ioctl failed: Invalid argument” – error on running lvcreate/lvresize/lvextend
  10. Unable to login with GUI on CentOS/RHEL 7

You May Also Like

Primary Sidebar

Recent Posts

  • pw-cat Command Examples in Linux
  • pvs: command not found
  • pulseaudio: command not found
  • pulseaudio Command Examples in Linux

© 2023 · The Geek Diary

  • Archives
  • Contact Us
  • Copyright