You are not logged in.

#1 2008-11-25 04:24:21

brando56894
Member
From: NYC
Registered: 2008-08-03
Posts: 681

Deleting Logs Based On Date

I have a lot of old logs in my /var/log directory that I always forget to delete and they just add to the clutter of the folder. How could I write a script that will delete a log if its older than, lets say, 2 weeks?

Offline

#2 2008-11-25 05:31:41

peart
Member
From: Kanuckistan
Registered: 2003-07-28
Posts: 510

Re: Deleting Logs Based On Date

I believe the cleanest way to achieve that would be to modify /etc/logrotate.conf.

# see "man logrotate" for details
# rotate log files weekly
weekly

# keep 4 weeks worth of backlogs
rotate 4

Offline

#3 2008-11-25 18:08:43

brando56894
Member
From: NYC
Registered: 2008-08-03
Posts: 681

Re: Deleting Logs Based On Date

awesome thanks

Offline

#4 2008-11-25 18:49:23

.:B:.
Forum Fellow
Registered: 2006-11-26
Posts: 5,819
Website

Re: Deleting Logs Based On Date

An even better solution is to archive the logs - have logrotate gzip them and dump them in a subdir of /var/log, so you keep it clean. Logs might always come in handy wink.


Got Leenucks? :: Arch: Power in simplicity :: Get Counted! Registered Linux User #392717 :: Blog thingy

Offline

Board footer

Powered by FluxBB