Solved

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

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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Using 'screen' for session sharing, The Simple Edition Step 1: user starts session with command: screen Step 2: other user (logged in with same user account) connects with command: screen -x Done. Both users are connected to the same CLI sessio…
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…
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.:
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

760 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

18 Experts available now in Live!

Get 1:1 Help Now