Skip to content
Advertisement

How to keep service script output from clogging up “messages”

I have a service on Centos7 that runs a script in /usr/local/sbin/restarthelp2.sh and outputs a tunnel check by checking the status of network connection. The output of this ends up in /var/log/messages and makes the file huge. I already have the output being sent to its own log file, how do I keep the output results from the script/service out of the “messages” file?

JavaScript

Code for the script mentioned above:

JavaScript

Advertisement

Answer

You can add to your [Service] section of the Unit the line

JavaScript

so that this output is not logged to the journal, and from there to syslog. For other values see man systemd.exec.


If you are using rsyslogd you can filter messages much later, just before they get put in /var/log/messages. Remove the above Unit line to get back to normal logging. Look for a file like /etc/rsyslog.conf and a line like

JavaScript

Add in front of this line a filter that compares a property with what you want to suppress, and use the action stop, for example one of:

JavaScript

There is extensive rsyslog documentation, but it is hard to follow as there are many old formats that are still supported, so you must be careful not to mix them up.

If you also change the Unit StandardOutput=null to StandardOutput=syslog, you will no longer get the messages logged in the systemd journal, and they will go straight to rsyslogd. I don’t know if this will provide you with the status information you wanted though.

User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement