On 2023-05-10 11:11, Per Jessen wrote:
I just want to check I'm not going bonkers.
From the logrotate man page:
--------------- preremove script endscript
The script is executed once just before removal of a log file. logrotate will pass the name of file which is soon to be removed as the first argument to the script. See also firstaction and the SCRIPTS section. --------------
So it sounds reasonable to expect "script" to be invoked with one argument, the name of the to-be-removed file. Right?
...
When I run a logrotate (either with systemd or manually), it does invoke the preremove script, but without the filename as argument, so my script leaves with a 75.
The man says: SCRIPTS The lines between the starting keyword (e.g. prerotate) and endscript (both of which must appear on lines by themselves) are executed (using /bin/sh). The script inherits some traits from the logrotate process, including stderr, stdout, the current directory, the environment, and the umask. Scripts are run as the invoking user and group, irrespective of any su directive. If the --log flag was specified, file descriptor 3 is the log file. So perhaps you can do: ---------------- /var/log/testfile { compress nodateext maxage 365 rotate 5 missingok notifempty size 1k sharedscripts postrotate /usr/bin/true endscript preremove /usr/local/bin/archive_logfile.sh /var/log/testfile endscript } ------------------- It is not what you wish, but would do. Even I understand you can do: ---------------- /var/log/testfile { compress nodateext maxage 365 rotate 5 missingok notifempty size 1k sharedscripts postrotate /usr/bin/true endscript preremove test -n "$1" || exit 75 log="$1" plus the rest endscript } ------------------- Looking at the existing rotate files, they actually do put scripts in there: /etc/logrotate.d/acct: var/log/account/pacct { compress dateext maxage 365 rotate 99 size=+4096k notifempty missingok create 640 root root postrotate /usr/bin/systemctl try-restart acct.service endscript } /etc/logrotate.d/chrony: var/log/chrony/*.log { su chrony chrony missingok nocreate sharedscripts postrotate /usr/bin/chronyc cyclelogs > /dev/null 2>&1 || true endscript } /etc/logrotate.d/mariadb has a long script. -- Cheers / Saludos, Carlos E. R. (from 15.4 x86_64 at Telcontar)