Unix & Linux Asked on December 6, 2020
How can I write a rainerscript
rule to log to a file whose name is a substring of $programname
?
I want something along the lines of this pseudo-rule:
if $programname startswith "foo" then /path/to/<substring of $programname from 4 to end>
Also: is there a way to strip the "foo" prefix from $programname
in the text that gets written to file?
Actually I'm feeling unhelpful with my comment to the OP. I did some more testing and here's a solid answer that I'd like to share:
Create /etc/rsyslog.d/00-local.conf with the following:
template(name="AdminLog" type="string" string="/var/log/admin_%syslogtag:R,ERE,1,ZERO::(.*):--end%")
if ($programname == "admin") then {
action(type="omfile" dynaFile="AdminLog")
stop
}
systemctl restart rsyslog
logger -t admin:backup starting
That results in /var/log/admin_backup getting the log.
Notes:
sudo -s
.set $.thefunction = re_extract($syslogtag,...)
Answered by TonyG on December 6, 2020
Get help from others!
Recent Answers
Recent Questions
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP