On Wed, 10 May 2023 11:11:36 +0200
Per Jessen
I just want to check I'm not going bonkers.
From the logrotate man page:
Which logrotate man page? Which version of logrotate on which system version? I ask because when I google, some versions of the man page don't even have a premove directive.
--------------- 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?
Kind of, but the repeated [elsewhere] mention of 'first' implies there might be more than one argument. But I can't find any trace of it. Just lots of discussion of quoting so filenames with spaces can be handled. Also, where is the SCRIPTS section? I can't find it.
the logrotate config - it is a test-setup, for rotating /var/log/testfile when it exceeds 1k, without date extension.
---------------- /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 endscript } -------------------
What's the point of the /usr/bin/true? I don't understand what that postrotate does.
My script /usr/local/bin/archive_logfile.sh contains
#!/bin/sh test -n "$1" || exit 75
log="$1" plus the rest
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.
I'd be trying to print as much as possible from the execution of archive_logfile.sh (use -x?, print any and all args etc)