Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I rotate Nginx logs daily (with dateext). After the rotation I want to parse the file for the day that just passed and compile an email with the number of errors returned by Nginx server.

How can I access the output file in the postrotate / endscript section of logrotate ?

share|improve this question
    
Can you elaborate more? –  Khaled Nov 1 '10 at 11:09
    
Done. Sorry, I thought it's clear enough. :) –  ibz Nov 2 '10 at 2:37
add comment

2 Answers

up vote 2 down vote accepted

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?

share|improve this answer
    
I thought the problem is irrelevant. Explained it in more detail now. Yes, I can just use the date to get the file name, but I was hoping I can get it through some variable or something, which would make more sense. –  ibz Nov 2 '10 at 2:39
3  
Looks like larsks has hit on exactly what you want. $1 is the variable you're looking for. –  mark Nov 2 '10 at 11:10
add comment

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.

share|improve this answer
1  
Handy. Actually, both the pre and post-rotate script appear to receive the rotated file name as $1, which is exactly what the question asks for. –  mark Nov 2 '10 at 11:06
add comment

Your Answer

 
discard

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.