LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   how can I redirect the messages sent from kernel to a user app's stdin? (https://www.linuxquestions.org/questions/linux-newbie-8/how-can-i-redirect-the-messages-sent-from-kernel-to-a-user-app%27s-stdin-897619/)

thehadar 08-16-2011 10:14 AM

how can I redirect the messages sent from kernel to a user app's stdin?
 
Hi,

I have an application that prints to a log what it gets from its stdin. I would like this application to also print to log messages the kernel creates(I.e. the same messages displayed by dmesg app).
How can I do it?

In other words, can I redirect the kernel messages (I.e. sent using printk) to an application's stdin pipe?

Thanks!
Hadar

kbp 08-17-2011 11:49 PM

rsyslog supports "named pipes" and "shell execute" actions, may one of these would suit. See 'man rsyslog.conf'

thehadar 08-18-2011 01:36 AM

Thanks. I already found a different solution. I sent /proc/kmsg and other applications' stdout to a fifo, and use this fifo as an input file to my application.

Something like this:

mkfifo /tmp/misfifo;
cat /proc/kmsg > /tmp/misfifo &
... # Send other appluications logs to myfifo. E.g. ./CoolApp > /tmp/misfifo &
./MyApp < /tmp/misfifo # Use misfifo as an input file to my application

It works.
Thanks again!
Hadar

kbp 08-18-2011 09:57 PM

Cool, but doing "cat /proc/kmsg > /tmp/misfifo" is a manual process as opposed to redirecting automatically via rsyslog

kernel -> rsyslog -> named pipe/fifo -> your app


All times are GMT -5. The time now is 02:10 PM.