I have set up syslog-ng to tail a file and forward each new event to python script which will process it.
My syslog-ng.conf looks like this -
source s_src {
file("/var/log/xyz.log" flags(no_parse);
};
destination d_dest {
program("python -u /home/user1/processlog.py" flush_lines(1) flags(no_multi_line));
};
log { source(s_src); destination(d_dest); };
And processlog.py just contains
#!/usr/bin/python
import sys
f1 = open('success.txt', 'a')
while 0 < 1:
try:
line = sys.stdin.readline()
f1.write(line)
except Exception, e:
f = open('/tmp/error.txt','ab')
f.write(e)
f.close()
exit(0)
This script works prefectly fine from command line. Takes each input and writes to success.txt.
Syslog-ng also starts but does not forward the event to python program above. It starts the program though.
ps -ef| grep processlog
root 6242 6236 0 13:00 ? 00:00:00 /bin/sh -c python -u /home/user1/processlog.py
root 6244 6242 0 13:00 ? 00:00:00 python -u /home/user1/processlog.py
I have checked all permissions too. But whenever new event happens in xyz.log, it is not getting forwarded to python script, which i am testing via writing to success.txt
Any leads are highly appreciated.