When to use sharedscripts in a Logrotate Configuration?

Hello All,

OS: SLES 11.3 x86_64

Should I be using the sharedscripts config command for my logrotate configuration, given the info below?

I made it so the server sending the log data will do Syslog pushes of 3 types of logs to my SLES server, and all 3 logs will be written into the same directory.

These log files are called:

/opt/host1/logs/host1_access.log
/opt/host1/logs/host1_amp.log
/opt/host1/logs/host1_trafmon.log

I then have the following configured for Logrotate for those 3 logs, see below...

Logrotate Configuration File: /etc/logrotate.d/host1_logs

/opt/host1/logs/host1*.log {
    daily
    rotate 7
    missingok
    compress
    compresscmd /usr/bin/gzip
    delaycompress
    dateext
#   ??sharedscripts??
    postrotate
        /etc/init.d/syslog reload > /dev/null
    endscript
}

I was a little bit confused whether or not I needed to have the sharedscripts command in there or not for my given configuration.

Would I want this to execute only once since it's rotating 3 log files (*sharedscripts) or have it run each time one of those 3 log files are rotated (*nosharedscripts)?

Any suggestions would be greatly appreciated!

Thanks in Advance,
Matt

Hello Matt,

Have a look at the man page:
man logrotate / man logrotate.conf .

You are on the right track. Sharedscripts portion reproduced here.

sharedscripts
Normally, prerotate and postrotate scripts are run for each log which is rotated and the absolute path to the log file is passed as first argument to the script. That means a single script may be run multiple times for log file entries which match multiple files (such as the /var/log/news/* example). If sharedscripts is specified, the scripts are only run once, no matter how many logs match the wildcarded pattern, and whole pattern is passed to them. However, if none of the logs in the pattern require rotating, the scripts will not be run at all. If the scripts exit with error, the remaining actions will not be executed for any logs. This option overrides the nosharedscripts option and implies create option.

Your use looks correct to me.

Cheers,

Nandan

1 Like

Hi Nandan, thanks for the reply, much appreciated!

Ok, so if I have 3 logs that will match my logrotate configuration section, shown in my OP, and they are all going to be rotated at the same time (*since I'm using daily instead of rotating on size) then using sharedscripts would be ok to restart syslog just the one time instead of restarting it 3 separate times.?

If that's correct, then I guess I would want to use that config command....

Thanks Again,
Matt

Hi Matt,

On re-reading the blurb about sharedscripts, it looks like sharedscripts will trigger if at least one log matches the criteria in your config. On the flip side, no sharedscripts will run, if none of the logs match the criteria.

Daily means your specified logs are getting evaluated every day, even though logrotate might run at a higher frequency.

And yes, syslog will reload only once when all three logs get rotated on the daily schedule.

Nandan

1 Like