2

I want to write a program that monitors syslog and performs an action when PPP authentication fails.

I think "tail -f /var/log/syslog" could help, but I'm not sure how to use it... probably using pipes?

I have found something similar written in bash, but I'm not sure how to implement it in C.

This is the bash method:

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
Mikel
  • 24,855
  • 8
  • 65
  • 66
capsula
  • 498
  • 1
  • 7
  • 21

2 Answers2

4

Finally I could found the solution!!

The solution was using named pipes!

First, I need to create a named pipe: mkfifo /pipe

Then, I feed the pipe with the log info: tail -f /var/log/syslog > /pipe

And then, I read the pipe from the C program using OPEN

int pipefd;
pipefd = open("/tmp/myFIFO", O_WRONLY);
capsula
  • 498
  • 1
  • 7
  • 21
0

Try to use inotify function. Using it you can monitor if a file or directory has changed.

Patryk
  • 1,421
  • 8
  • 21