0

My knowledge about bash are poor, so I have the following logrotate configuration for squid, and I trying to pass resulting log file name (access-Y-m-d.log) that includes the previous date in the name, to another shell script that calls a symfony command with the name of resulting file as parameter. Currently I generate expected filename inside the symfony command, but I want generate it from the beginning (postrotate section).

    /var/log/squid/access.log {
    su root root
    daily
    missingok
    rotate 999
    extension .log
    dateext
    dateyesterday
    dateformat -%Y-%m-%d
    nocompress
    nomail
    notifempty
    create 0644 proxy proxy
    sharedscripts
    ifempty
    #prerotate
    #endscript
    postrotate
        test ! -e /run/squid.pid || test ! -x /usr/sbin/squid || /usr/sbin/squid -k rotate
        # Este script se encarga de copiar el archivo rotado al directorio de respaldo local y al FTP configurados;
        **resultingFilename=????????**
        /var/www/html/squidmgr/run/rotarsquid.sh $resultingFilename > /dev/null 2>&1
    endscript
}

/var/www/html/squidmgr/run/rotarsquid.sh:
rotatedLogFilename=$1
sudo -u www-data php -d memory_limit=256M /var/www/html/squidmgr/bin/console squidmgr:backups:squid-access-log-postrotate $rotatedLogFilename --notify-to-users-on-success --dump-to-db > /dev/null 2>&1
exit 0

The second script call symfony command with $rotatedLogFilename as argument.

2 Answers 2

1

You could use a prerotate script to read the log file before it's rotated:

prerotate
    /some/path/myscript "$1" >/dev/null 2>&1
endscript

The various script sections get the name of the log file as their first argument, and it is available in "$1". In the prerotate script, you have access to the log file before it is rotated, so reading the log file there (or copying it or whatever you need to do) is possible by using that argument.

1
  • Ohh tank you, I hadn't thought about that option!!!!!
    – Francisco
    Commented Oct 24, 2023 at 13:52
0

I have found the solution, inside postrotate section:

postorate
    YESTERDAYSTR=$(date -d "1 day ago" '+%Y-%m-%d');
    RESULTINGFILENAME="access-$YESTERDAYSTR.log";
    /var/www/html/squidmgr/run/rotarsquid.sh $RESULTINGFILENAME > /dev/null 2>&1
endscript

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .