Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

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

Posted on 2015-02-24
4
Medium Priority
?
250 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
  • 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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

I. Introduction There's an interesting discussion going on now in an Experts Exchange Group — Attachments with no extension (http://www.experts-exchange.com/discussions/210281/Attachments-with-no-extension.html). This reminded me of questions tha…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
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…
Connecting to an Amazon Linux EC2 Instance from Windows Using PuTTY.
Suggested Courses
Course of the Month9 days, 12 hours left to enroll

879 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