Solved

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

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

U.S. Department of Agriculture and Acronis Access

With the new era of mobile computing, smartphones and tablets, wireless communications and cloud services, the USDA sought to take advantage of a mobilized workforce and the blurring lines between personal and corporate computing resources.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
a free alternative to cpanel? 1 58
Remove a folder in Linux 9 90
Printing to old printer through Linux (CUPS) Print Server? 7 46
How to learn Linux? 10 42
Introduction: The undo support, implementing a stack. Continuing from the eigth article about sudoku.   We need a mechanism to keep track of the digits entered so as to implement an undo mechanism.  This should be a ‘Last In First Out’ collec…
If you use Adobe Reader X it is possible you can't open OLE PDF documents in the standard. The reason is the 'save box mode' in adobe reader X. Many people think the protected Mode of adobe reader x is only to stop the write access. But this fe…
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
Learn how to navigate the file tree with the shell. Use pwd to print the current working directory: Use ls to list a directory's contents: Use cd to change to a new directory: Use wildcards instead of typing out long directory names: Use ../ to move…

912 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

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now