user3514522
user3514522

Reputation: 21

Logrotate settings: rotating, emailing and adding lines to archive log

I have a logrotate setting in logrotate.conf that doesn't want to run. What I'm trying to do is:

Rotate the log every day and truncate the log
Emailing me the rotated lines of the log
Adding the lines of the rotated log to a monthly archive
Create olddir rotated/ if it doesn't exist yet

What am i missing here?

(log file path){
    daily
    rotate 0
    olddir rotated
    copytruncate
    nodateext
    missingok
    notifempty
    compress
    mailfirst
    mail email (at) email . com
    prerotate
        original = $1
        replacement = 'rotated'
        olddir_path = "${original/php-error.log/$replacement}"

        mkdir olddir_path
    endscript
    postrotate
        original = $1
        replacement = 'rotated'
        olddir_path = "${original/php-error.log/$replacement}"

        cat "${olddir_path}/php-error.log.1" >> "${olddir_path}/php-error-monthly.log"
    endscript
}

Upvotes: 2

Views: 564

Answers (1)

parttimeturtle
parttimeturtle

Reputation: 1215

You were great all the way up to "Create olddir rotate/ if it doesn't exist yet". Run logrotate -d /etc/logrotate.conf and I'll bet you get something like this back for that configuration:

error: /etc/logrotate.conf: error verifying olddir path rotated: No such file or directory

This is because that directory needs to exist at the time logrotate reads its configuration file; this is before any prerotate scripts are executed so naturally that directory does not exist and parsing the configuration fails. Make that directory first, however you'd like but first.

Upvotes: 0

Related Questions