FastNetMon

Wednesday 17 March 2010

Python: обработка строк по мере поступления

Для решения этой задачи есть суперская утилита:
http://code.google.com/p/pytailer/


Ставим Python и easy_install:

apt-get install -y python python-setuptools


На CentOS команды иные:
yum install -y python-setuptools


Ставим tailer:

easy_install tailer


Пишем скрипт:

#!/usr/bin/python
# -*- coding: utf-8 -*-

import tailer

for line in tailer.follow(open('/var/log/nginx/access.log')):
print line


Вот и все, можно теперь любым способом обрабатывать приходящие строки.

No comments :

Post a Comment

Note: only a member of this blog may post a comment.