Logrotate: how to access the output file in postrotate

I'm not aware of any variables you can use if that's what you're looking for. However immediately after rotating the log, you should know precisely the name that the file has been rotated to based on the configuration you've set for the rotation (/var/log/somefile.1 or the like).

Perhaps it would be easier to answer if you described actual problem you're trying to solve?


If you are not using the "sharedscripts" directive, then your postrotate script receives, as $1, the file that triggered the log rotation. This might help if you're trying to use a generic script with multiple logrotate stanzas. That is, given something like this:

/var/log/sample1.log /var/log/sample[23].log {
  ..config...
}

If any matching files needs to be rotated, your script will be called with $1 set to "/var/log/sample1.log", "/var/log/sample2.log", or "/var/log/sample3.log" as appropriate. You can then append ".1" to find the file that was just rotated.

If you use the "sharedscripts" option, then you script would be called with $1 set to "/var/log/sample1.log /var/log/sample[23].log" (which will help you identify a particular stanza but not the exact file).

Hopefully this gives you a place to start. Note that this will only work for logrotate > v3.7.5.