3

According to the documentation I can execute a program somewhat like so:

destination knotifier { program('/path/to/executable'; };

And it will send the log to the stdin of the executable. But what if the program I'm executing would need the input as an argument to an option? Is there a way to do that? Or do I have to write a wrapper for the program I'm executing?

tshepang
  • 64,472
  • 86
  • 223
  • 290
xenoterracide
  • 57,918
  • 74
  • 184
  • 250

2 Answers2

0

If I understand you correctly and if this is on Linux, you may try using

/proc/self/fd/0

as the argument. This should be a symlink to the standard input of the process. Equivalently, on some systems, you could use

/dev/stdin

which is often just a symlink to /proc/self/fd/0. I don't have a system with syslog-ng to test this on, but I think something like the following should work:

destination knotifier { program('/path/to/executable -i /proc/self/fd/0'); };

where -i would be substituted for whatever command line switch the executable needs if any. I've also seen /dev/fd/0 used, but I tend to stick with using /proc directly. For more info see man proc.

Steven D
  • 45,310
  • 13
  • 119
  • 114
0

For most commands a wrapper will have to be written because Syslog-ng will only execute the command when it starts. This means that the command has to effectively be a daemon itself always accepting input from stdin.

That's simple though...

#!/bin/dash

while read line
do
    /execute/my/app $line
done

unfortunately this script doesn't work for me, probably because it doesn't know which display to use. But if your script doesn't need an X server then a simple format like this should work you.

Although this is no way helpful due to the fact that Syslog-ng will only start the program on startup I found the fact that xargs can create positional arguments from standard input interesting.

echo 'test' | /usr/bin/xargs -I '{}' /usr/bin/kdialog --passivepopup '{}' 2
xenoterracide
  • 57,918
  • 74
  • 184
  • 250