Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I want to schedule logs rotate with these rules:

  1. log files for the last 2 day are kept untouched
  2. log files older than 2 days are archived and moved to folder named by date, they were created. (For ex. All logs for 01 Dec 2012 are moved to 20121201 and archived.)
  3. log files older than 14 days are removed.

I want to use logrotate for this, but I'm not sure it suits my needs or not.

I'd like something like this, but it doesn't work.

/mylog/* {   
DIR=$(date +%y%m%d); // actually it's current date
mkdir $DIR
rotate 2
olddir /mylog/$DIR
       find /mylog -type d -mtime +180 | xargs rm -f

Logrotate does not understand that $DIR is variable.

Any suggestions are welcome!

share|improve this question
up vote 1 down vote accepted

According to @koniu from superuser, it is not possible. As far as I checked, I didn't find any other ways for that.

For the age of the log, you have a maxage directive which according to the manpage:

   maxage count
          Remove  rotated  logs  older  than <count> days. The age is only
          checked if the logfile is to be rotated. The files are mailed to
          the configured address if maillast and mail are configured.

Looks like it doesn't work on old logs moved in olddir.

share|improve this answer
Thanks for the link. It covers the question about olddir. It's a bit tricky, but it should work! It was really helpful. Am I right, that logrotate can not delete old logs from olddir? Should my solution in postrotate work? – user148378 Dec 5 '12 at 13:04

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.