How to configure logrotate to delete DA logs

MagnuM

Verified User
Joined
Oct 24, 2003
Messages
102
Location
Romania
Hello, I want to ask how can I configure the logrotate.conf file so the DirectAdmin logs to be deleted weekly, adn also if they are greater than 1 MB?

If some of have a valid script, whish is tested and working good, plese send it to me.

Thanks.
 
create a file in /etc/logrotate.d/ with the following content:

/path/to/log/file/mylogfile {
size=1M
weekly
}
 
Actualy the point is that in /var/log/directadmin/ I have a lot of log files and some of them are 3 months old:

-rw------- 1 diradmin diradmin 10572 May 17 00:19 2004-May-16.log
-rw------- 1 diradmin diradmin 5126 May 17 19:17 2004-May-17.log
-rw------- 1 diradmin diradmin 5302 May 18 14:04 2004-May-18.log
-rw------- 1 diradmin diradmin 4473 May 20 18:07 2004-May-20.log
-rw------- 1 diradmin diradmin 6070 May 21 20:30 2004-May-21.log
-rw------- 1 diradmin diradmin 2711 May 23 12:02 2004-May-23.log
-rw------- 1 diradmin diradmin 2448 May 24 14:24 2004-May-24.log
-rw------- 1 diradmin diradmin 3331 May 25 01:10 2004-May-25.log
-rw------- 1 diradmin diradmin 4198 May 26 13:18 2004-May-26.log
-rw------- 1 diradmin diradmin 4590 May 27 17:23 2004-May-27.log
-rw------- 1 diradmin diradmin 7008 May 28 18:15 2004-May-28.log
-rw------- 1 diradmin diradmin 3320 May 30 04:09 2004-May-30.log

And I would like to delete all files from DirectAdmin which are older than 1 month or greater than 10 MB.

I think there are enough log files left there to read if a problem appears.

So as you said, I have create this code:

/var/log/directadmin/ {
weekly
size=1M
rotate 0
}

and put it to /etc/logrotate.conf asa I read in logrotate docs. Then I run: logrotate /etc/logrotate.conf , ad guess what nothig happens :) The files are still there.
 
ok, this seems to work.

content of /etc/logrotate.d/directadmin:

/var/log/directadmin/*.log {
weekly
size=1M
rotate=0
create 0644 diradmin diradmin
sharedscripts
postrotate
find /var/log/directadmin -name "20*log*" -mtime +7 -exec /bin/rm -f {} \;
find /var/log/directadmin -name "20*log.?" -exec /bin/rm -f {} \;
endscript
}

I then ran logrotate -f /etc/logrotate.d/directadmin after making the change
 
Thanks, I try it, it works, but there is a little problem:
- all files from /var/log/directadmin/ are deleted and then recreated again (empty of course)

The point is that I want to delete only the file older than one month (not one week, it's too quickly), and not recreate them. The DirectAdmin software will create them if they are missing.

One question, what does this line doing:
find /var/log/directadmin -name "20*log.?" -exec /bin/rm -f {} \;?
 
to delete file more than 1 month change to this:

find /var/log/directadmin -name "20*log*" -mtime +30 -exec /bin/rm -f {} \;

and as for this,

find /var/log/directadmin -name "20*log.?" -exec /bin/rm -f {} \;

It is only needed if you are rotating logs, which your not, because your using rotate=0, so, just eliminate that line. My mystake.
 
drop the create 0644 diradmin diradmin line if you don't want it to create empty files.
 
The right code looks like this:

/var/log/directadmin/*.log {
weekly
size=1M
rotate=0
sharedscripts
postrotate
find /var/log/directadmin -name "20*log*" -mtime +30 -exec /bin/rm -f {} \;
endscript
}
 
Back
Top