Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

HOW TO use fabric use with dtach,screen,is there some example

Tags:

python

fabric

i have googled a lot,and in fabric faq also said use screen dtach with it ,but didn't find how to implement it? bellow is my wrong code,the sh will not execute as excepted it is a nohup task

def dispatch():
    run("cd /export/workspace/build/ && if [ -f spider-fetcher.zip ];then mv spider-fetcher.zip spider-fetcher.zip.bak;fi")
    put("/root/build/spider-fetcher.zip","/export/workspace/build/")
    run("cd /export/script/ && sh ./restartCrawl.sh && echo 'finished'")
like image 645
maolingzhi Avatar asked Feb 22 '12 10:02

maolingzhi


2 Answers

I've managed to do it in two steps:

  1. Start tmux session on remote server in detached mode:

    run("tmux new -d -s foo")

  2. Send command to the detached tmux session:

    run("tmux send -t foo.0 ls ENTER")

here '-t' determines target session ('foo') and 'foo.0' tells the number of the pane the 'ls' command is to be executed in.

like image 70
Dragan Cvetinovic Avatar answered Oct 05 '22 23:10

Dragan Cvetinovic


you can just prepend screen to the command you want to run: run("screen long running command")

Fabric though doesn't keep state like something like expect would, as each run/sudo/etc are their own sperate command runs without knowing the state of the last command. Eg run("cd /var");run("pwd") will not print /var but the home dir of the user who has logged into the box.

like image 35
Morgan Avatar answered Oct 05 '22 23:10

Morgan