0

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 package.zip with a name like this :

log_from_2012_08_14-11:57:12_To_2012_09_14-13:57:12.zip 

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

/var/trafficap/captured/arch/*zip {
daily
compress
prerotate
if [[ ! -d `date +%F` ]]
then
 mkdir `date +%F`
fi
endscript
}

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

Scott Pack
  • 14,907
  • 10
  • 53
  • 83

2 Answers2

0

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.

mdpc
  • 11,856
  • 28
  • 53
  • 67
  • 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
0

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.

Alex
  • 3,129
  • 21
  • 28
  • 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 02 '12 at 17:03