Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can't get Fabric's detached screen session example to work

Tags:

python

fabric

I am trying to execute a script on a remote host using a detached screen session. I tried out the example Fabric gives and unfortunately couldn't get it to work.

from fabric.api import run

def yes():
    run('screen -d -m "yes"')

Executing fab yes on my local machine correctly connects it to the remote host and says the command has been run, however nothing is executed on the remote host. Trying screen -d -m "yes" on either machine works as expected.

If anyone could point out what I'm doing wrong I'd greatly appreciate it. Also, on a side note, why are there quotes around the yes in the command? Would it work without the quotes? Thanks!

like image 386
FastTurtle Avatar asked Jan 14 '13 22:01

FastTurtle


People also ask

How do you detach from a screen in Python?

Ctrl-a + d: It detach a screen session without stopping it. Ctrl-a + r: It reattach a detached screen session.

How do I remove a detached screen in Linux?

There are 2 (two) ways to leaving the screen. First, we are using “Ctrl-A” and “d” to detach the screen. Second, we can use the exit command to terminating the screen. You also can use “Ctrl-A” and “K” to kill the screen.

What does detached screen mean?

Detaching screen means exit from screen but you can still resume the screen later. To resume screen you can use screen -r commmand from the terminal.


2 Answers

run('screen -d -m yes; sleep 1') works.

Not sure if Fabric or screen are to blame for this behaviour though.

like image 189
AVB Avatar answered Nov 15 '22 09:11

AVB


Although AVB answer is perfect I'll add a small tip which may help someone like me. If you want to run more than one command put them to a executable file.

This will not work:

run('screen -d -m "./ENV/bin/activate; python run.py; sleep 1"')

So create a run.sh file:

#!/bin/bash
source ENV/bin/activate
python run.py

And use it like run('screen -d -m ./run.sh; sleep 1')

like image 24
kerma Avatar answered Nov 15 '22 08:11

kerma