• 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 split iso or file using ‘split’ command in Linux
  2. How to mount USB flash drive in Linux
  3. Understanding Linux SCSI Reservation
  4. dpkg-deb: command not found
  5. Unable to start Nagios Service (CentOS/RHEL)
  6. Choosing SSSD or Winbind & Samba for Active Directory Integration in CentOS/RHEL
  7. How to Count lines in a file in UNIX/Linux
  8. ifenslave Command Examples in Linux
  9. How to configure DM-Multipath from an iSCSI initiator to an iSCSI target in CentOS / RHEL
  10. locate Command Examples in Linux

You May Also Like

Primary Sidebar

Recent Posts

  • grpck command – Remove corrupt or duplicate entries in the /etc/group and /etc/gshadow files.
  • xxd command – Expressed in hexadecimal form
  • sesearch: command not found
  • macof: command not found

© 2022 · The Geek Diary

  • Archives
  • Contact Us
  • Copyright