-1

I'm trying to pass a custom formatted date as part of the olddir path in my logrotate configuration since I organize my archives chronologically (obviously!).

This is what I'm passing to olddir :

olddir /path/to/archive/$(date --date='-1 day' +'%Y/%m-%b')/

Running logrotate -d (debug mode) throws me this error :

error: /etc/logrotate.d/my-logrotate-config:15 bad olddir path /path/to/archive/$(date --date='-1 day' +'%Y/%m-%b')/

Is there some way I can pass the output of the date command to the olddir option?

shine
  • 69
  • 1
  • 2
  • 4

1 Answers1

0

This won't work this way, as we can't pass the olddir as a switch to the logrotate command (which would make it interpretable by bash). The logrotate config file isn't run through the shell, so we can't use shell conventions in it. Everything in it is literal, aside from comments and the like.

What you could do is logrotate to a common directory (statically defined in the logrotate.conf file, as one would have to be), and then immediately moved kind like this, but maybe in a better way than I wrote it:

#!/bin/bash logrotate mkdir /path/to/archive/$(date --date='-1 day' +'%Y/%m-%b')/ mv /path/to/common/logrotate/dumping/ground/* /path/to/archive/$(date --date='-1 day' +'%Y/%m-%b')/

Spooler
  • 7,046
  • 18
  • 29
  • You basically mean to make a bash script to do the organizing part right? The primary reason I switched to logrotate was to avoid redundant scripting. But if this is the only way to achieve this, I'd rather stick to my existing bash script that does the whole thing for me. But thanks a lot for your answer @smallloanof1m – shine Oct 11 '16 at 12:37
  • another question that arises from your answer is where you mentioned that logrotate doesn't use the shell. If it doesn't, then it won't be able to access other binaries installed on the system, would it? like `nc` or `scp` right? – shine Oct 11 '16 at 12:40