When to use sharedscripts in a Logrotate Configuration?


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers When to use sharedscripts in a Logrotate Configuration?
# 1  
Old 05-04-2016
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:
Code:
/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
Code:
/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
# 2  
Old 05-04-2016
Use of shatedscripts

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
This User Gave Thanks to nandanlbhat For This Post:
# 3  
Old 05-05-2016
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
# 4  
Old 05-05-2016
Use of shatedscripts

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
This User Gave Thanks to nandanlbhat For This Post:
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Problem with logrotate

Hi, I have a problem with logrotate at Centos 7. My logrotate is configured with "rotate 0" to Apache logs, so it should never keep logs when rotating, just removing them and replacing by new empty ones at every rotation. But for some reason, once in a while, I see that logrotate is creating... (0 Replies)
Discussion started by: dado000
0 Replies

2. UNIX for Dummies Questions & Answers

Logrotate configuration

Hi all, i would like to have a configuration on log rotate that will gzip my log files with date pattern %Y-%m-%d move these files to an olddir, but i want to avoid that the logrotate removes my files from old dir newer than 180 days i applyied this config #logrotate config to compress files... (3 Replies)
Discussion started by: charli1
3 Replies

3. AIX

Logrotate.conf

Hey Admins, I have installed logrotate on AIX server. I want to configure it for 1. /var/log/messages – keep 90 days, i.e., weekly rotate 13 2. Syslog – keep 90 days i.e., weekly rotate 13 3. Wtmp – keep 90 days i.e., weekly rotate 13 4. Sulog – keep 90 days i.e., weekly rotate 13 What... (1 Reply)
Discussion started by: snchaudhari2
1 Replies

4. AIX

Logrotate - /etc/logrotate.conf does't exist

Hi Admins. I have installed logrotate rpm on Aix 6.1. After the installation of rpm, I don't find /etc/logrotate.conf file and /etc/logrotate.d dir . The config file is located in /opt/freeware/etc/logrotate.conf. When I ran logrotate -v /opt/freeware/etc/logrotate.conf I get below... (2 Replies)
Discussion started by: snchaudhari2
2 Replies

5. Shell Programming and Scripting

Logrotate - I am not able to rotate files using logrotate

I have written script which is working in Home directory perfectly and also compressing log files and rotating correctly. But, when i try to run script for /var/log/ i am able to get compressed log files but not able to get rotation of compressed log files. Please suggest. I am using below command... (5 Replies)
Discussion started by: VSom007
5 Replies

6. Red Hat

Logrotate on RHEL 5

Hi All, Can any one let me me know if i run /usr/sbin/logrotate /etc/logrotate.conf will it read the whole /var/log/messages or it just see the time stamp of message file & then rotate the logs. Just wants to know is logrotation based on messages file contents or messages file time stamp. ... (1 Reply)
Discussion started by: ajaincv
1 Replies

7. UNIX for Advanced & Expert Users

rotate modsec log with logrotate in the global configuration

Hello Experts, I have an apache 2.2.17 on solaris 10 that I am not sure if I, could list the following in the global settings in httpd.conf. I tested it in the Virtual host section of httpd.conf and, it works but, not sure if I can do it in the global settings. Any help would be greatly... (0 Replies)
Discussion started by: afadaghi
0 Replies

8. Linux

LogRotate

Hi I am trying to rotate specific log by using logrotate function in unix I have made following entry in the /etc/logrotate.conf file /var/log/testlog/debug_log { daily rotate 7 create compress } But only issue is that my other logs like /var/log/messages,... (2 Replies)
Discussion started by: SiddhV
2 Replies

9. UNIX for Advanced & Expert Users

Logrotate configuration problem

Hi, I have the following configuration file: /logs/system/mindundi/* { rotate 0 daily missingok sharedscripts postrotate find /logs/system/mindundi/ -name "*log" -mtime +15 -exec /bin/rm -f {} \; endscript } I want to save only... (6 Replies)
Discussion started by: mitchbcn
6 Replies

10. UNIX for Advanced & Expert Users

logrotate with /etc/logrotate.conf file

Hi there, I want to rotate the logfiles which are located in /var/log/jboss/tomcat* so I have created a file named as 'tomat' in /etc/logrotate.d/tomcat with the following content. # cat /etc/logrotate.d/tomcat /var/log/jboss/tomcat_access_log*.log { daily nocreate ... (2 Replies)
Discussion started by: skmdu
2 Replies
Login or Register to Ask a Question