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

Every day I would like to run logrotate on /var/trafficap/captured/arch/ and zip all the zip packages I have for each day ( its 1 with a name like this : 

For each 2 hours of trafic, and when I get to the daily schedule time of lograte he would create the of all todays .zip) and move it it everyday to a different dir just like this:

/var/trafficap/captured/arch/*zip {
if [[ ! -d `date +%F` ]]
 mkdir `date +%F`

but i don't know how to say "Logrotate please zip this files to the to the directory that is equal to $datedtoday that I created on the pre script\conf file"

share|improve this question

What about looking at the problem from the other way around? How about doing a postrotate routine that moves the file (after being rotated) to the appropriate destination with the appropriate name.

share|improve this answer
can be a solution but for that the question still remains how do i say "logrotate move the compress\rotated package to this dir that have the date of today" and then the day after do the same for all the days forever – drd0sPy Oct 31 '12 at 18:02

Straight from logrotate's man page

olddir directory

Logs are moved into directory for rotation. The directory must be on the same physical device as the log file being rotated, and is assumed to be relative to the directory holding the log file unless an absolute path name is specified. When this option is used all old versions of the log end up in directory. This option may be overridden by the noolddir option.

share|improve this answer
hmmm how can i set the olddir to be dynamic with each day ... like how to make him do assume this value : date %h%m%d – drd0sPy Oct 31 '12 at 19:46
If your script assigns 'date %h%m%d' to a variable, then you should be able to use it in logrotate. But this is a guess since I never used it that way – Alex Oct 31 '12 at 19:51
well it doesnt work but i did it like this : code /home/drd0s/teste/*zip { daily compress postrotate a=$(date +%Y-%m-%d) pastadhoje=$(ls -f | grep -c $a) if [ "$pastadhoje" -eq 0 ] then mkdir $a fi mv *.gz $a mv *.zip.1 $a endscript } code – drd0sPy Nov 2 '12 at 17:03

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.