Solved

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

Posted on 2015-02-24
4
234 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 500 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 500 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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

Little introduction about CP: CP is a command on linux that use to copy files and folder from one location to another location. Example usage of CP as follow: cp /myfoder /pathto/destination/folder/ cp abc.tar.gz /pathto/destination/folder/ab…
The purpose of this article is to demonstrate how we can use conditional statements using Python.
Connecting to an Amazon Linux EC2 Instance from Windows Using PuTTY.
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
Suggested Courses

630 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