journal-triggerd icon indicating copy to clipboard operation
journal-triggerd copied to clipboard

Trigger for shell script message

Open khurshid-alam opened this issue 8 years ago • 3 comments

I use logger or systemd-cat to send script output to systemd journald. For example a script named myscript99

#!/bin/bash
exec 1> >(logger -s -t $(basename $0)) 2>&1
echo "my pants are on fire!"

which can be filtered by journalctl using:

journalctl -t "myscript99"

I want to filter message both by identifier and message. My rule file looks like this:

[Rule]
trigger=~/.http_post.sh
[Filter]
SYSLOG_IDENTIFIER=myscript99
MESSAGE=*"fire"*

But it doesn't trigger anything. How does pattern matching work in this case?

khurshid-alam avatar Jun 16 '16 21:06 khurshid-alam

You need to use ?= to enable pattern matching; So you probably want your MESSAGE condition to be written as such: MESSAGE?=fire

Also I think your trigger isn't gonna work because this isn't a shell, there's no expansion, so you need to specify an actual path, e.g: /home/user/.http_post.sh

jjk-jacky avatar Jun 16 '16 22:06 jjk-jacky

Thanks. I will try. One other question: Is there any way I can pass MESSAGE and SYSLOG_IDENTIFIER t o my script (http_post.sh) as arguments?

khurshid-alam avatar Jun 17 '16 03:06 khurshid-alam

Sure: use $MESSAGE and $SYSLOG_IDENTIFIER -- See man page for more.

jjk-jacky avatar Jun 17 '16 07:06 jjk-jacky