Mezgani blog

August 2, 2009

Pipes in syslog

Filed under: bash, linux, system — Tags: — Ali MEZGANI @ 11:30 pm

Using syslog, there are a possiblity to write the output to a pipe, so we can read this pipe from a program. But we have to be careful, syslogd should not wedge but we will have missing and/or mangled
messages if they arrive faster than our program can process them.
Let’s take look to how to create these pipes and read from them:

First create a named pipe using mkfifo:
$ mkfifo -p /home/mezgani/syslog.pipe

Make syslog.conf to points to this file:
*.info |/home/mezgani/syslog.pipe

Restart syslog:
$ sudo pkill -HUP syslogd

Create processing script that read the pipe
$ cat > foo
#!/bin/bash
cat /home/mezgani/syslog.pipe | while read input
do
# some stuff
echo ${input}
# ….
done

Theme: Silver is the New Black. Blog at WordPress.com.

Follow

Get every new post delivered to your Inbox.