-1

I want to create a script with python flask or bottle module to print my /var/log/messages logs with tail -f command.

import subprocess
from bottle import route, response, run

@route("/")
def file():
    response.content_type = "text/plain"
    while True:
        return subprocess.check_output(["tail", "-4", "file"])

run(host='localhost', port=888)

when i try it with tail -f the page just hangs and loads for ever.

davidism
  • 121,510
  • 29
  • 395
  • 339
Adil
  • 3
  • 5

1 Answers1

1

tail -f\ actually block current thread, it neverreturn` until you terminate it.

https://github.com/seb-m/pyinotify or http://pythonhosted.org/watchdog/ Would be a better idea.

scriptboy
  • 777
  • 8
  • 25