Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

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?

share|improve this question

2 Answers 2

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.

share|improve this answer
    
this is awesome unfortunately I don't think the app (kdialog) that I'm using (which I don't/didn't think would matter) supports input from file. –  xenoterracide Sep 4 '10 at 19:47
    
Perhaps try something like kdialog cat /proc/self/fd/0``? –  Steven D Sep 4 '10 at 21:05
up vote 0 down vote accepted

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
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.