1

I'm trying to read log with tail -f with my fabric script:

@task
def log(service):
    sudo("tail -n 50 -f " + service)

With -f option you have to manually terminate tail by Ctrl-C. It doesn't work properly with fabric version (fab log:), Ctrl-C doesn't terminate remote command:

<remote-host>$ ps aux | grep tail
root     27314  0.0  0.0  33380  1744 ?        Ss   10:49   0:00 sudo -S -p sudo password: /bin/bash -l -c tail -n 50 -f /var/log/karma/gunicorn_gevent_error.log
root     27315  0.0  0.0   5592   584 ?        S    10:49   0:00 tail -n 50 -f /var/log/karma/gunicorn_gevent_error.log
... <they stack> ...
mezhenin 27337  0.0  0.0   7788   864 pts/8    R+   10:49   0:00 grep tail

What is correct way for doing things above?

Artem Mezhenin
  • 5,539
  • 6
  • 32
  • 51

1 Answers1

3

I've found correct solution for this problem. I need to use env.remote_interrupt = True:

env.remote_interrupt = True
env.LOG = '<path to log>'

@task
def log():
    assert(env.remote_interrupt == True)
    with settings(warn_only=True):
        sudo("tail -n 50 -f " + env.LOG)
Artem Mezhenin
  • 5,539
  • 6
  • 32
  • 51
  • This does not work with the latest Fabric 2. And I can't find the equivalent of remote_interrupt in the new doc. Any hint ? – glenfant Jul 29 '19 at 14:59
  • @glenfant I used the following ``connections = [...];ThreadingGroup.from_connections(connections).run("tail -f log")`` – gipi Nov 13 '20 at 14:33