Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

What is the best way to clean up log files on a syslog server.

Posted on 2015-02-24
4
Medium Priority
?
240 Views
Last Modified: 2015-02-25
We have a RHEL6 syslog servers to store all log files from many linux servers, those linux servers are running syslog client, and forward logs to this syslog server, the logfiles on this syslog server looks like this:

/var/log/syslog/server1/server1-date1.log
/var/log/syslog/server1/server1-date2.log
/var/log/syslog/server1/server1-date3.log
...

/var/log/syslog/server2/server2-date1.log
/var/log/syslog/server2/server2-date2.log
/var/log/syslog/server2/server2-date3.log
...

/var/log/syslog/server3/server3-date1.log
/var/log/syslog/server3/server3-date2.log
/var/log/syslog/server3/server3-date3.log
...

We want to clean up those log files regularly, for example to delete or move all "serverX-date1.log" and "serverX-date2log" to some where, and just keep all"serverX-date3.log" in that directory,

What is the best way doing this?
0
Comment
Question by:Joseph Gan
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 
LVL 21

Accepted Solution

by:
Mazdajai earned 2000 total points
ID: 40629754
Take a look of tmpwatch to rotate and archive old log files. It is come with rhel.
0
 
LVL 16

Author Comment

by:Joseph Gan
ID: 40629796
Thanks for quick reply.

From the man page: "tmpwatch - removes files which haven't been accessed for a period of time", it is nice and easy, thanks for that.

Just wondering how to use this command to "rotate and archive old log files", do you have an example?
0
 
LVL 21

Assisted Solution

by:Mazdajai
Mazdajai earned 2000 total points
ID: 40629877
Sorry I mean logrotate when I say tmpwatch, I used both on a regular basis to mange log files. logrotate allows you to rotate and archive (compress) files:

/var/http/access_log {
        size 1k
        copytruncate
        create 700 xyz xyz
        dateext
        rotate 4
        compress
}

Open in new window


Then you can use remove archive (.gz) that are older than x days:
find /var/http/  -mtime +7 -name "*.gz" -print -exec /bin/rm {} \;

Open in new window

0
 
LVL 16

Author Closing Comment

by:Joseph Gan
ID: 40631450
Great.
0

Featured Post

PowerShell Core for Advanced Linux Administrators

Understand advanced principals around Powershell Core with a focus on the Linux Administrator.  This course covers how to administer numerous environments across multiple platforms including Linux, Azure, AWS, and Google Cloud from a single shell instance.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
Join Greg Farro and Ethan Banks from Packet Pushers (http://packetpushers.net/podcast/podcasts/pq-show-93-smart-network-monitoring-paessler-sponsored/) and Greg Ross from Paessler (https://www.paessler.com/prtg) for a discussion about smart network …
Learn how to get help with Linux/Unix bash shell commands. Use help to read help documents for built in bash shell commands.: Use man to interface with the online reference manuals for shell commands.: Use man to search man pages for unknown command…
Learn how to find files with the shell using the find and locate commands. Use locate to find a needle in a haystack.: With locate, check if the file still exists.: Use find to get the actual location of the file.:
Suggested Courses

715 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question