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?
[Unit] Description=CHECK the wlan [Service] Type=simple ExecStart=/usr/local/sbin/restarthelp2.sh [Install] WantedBy=default.target
Code for the script mentioned above:
#!/bin/bash while true; do status=$(</sys/class/net/wlan0/operstate) tunstate=$(</sys/class/net/tun0/carrier) now=$(date) if [ $status == up ] && [ $tunstate -eq 1 ]; then echo "everything was good at $now, tunnel status was $tunstate" >> /var/log/wlancheck.log echo "tunnel status is UP" sleep 10 fi done
Advertisement
Answer
You can add to your [Service]
section of the Unit the line
StandardOutput=null
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
*.info;... /var/log/messages
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:
if $programname startswith "restarthelp" then stop if $msg contains 'tunnel status is UP' then stop
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.