maolingzhi
maolingzhi

Reputation: 691

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

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'")

Upvotes: 8

Views: 2275

Answers (2)

Dragan Cvetinovic
Dragan Cvetinovic

Reputation: 163

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.

Upvotes: 9

Morgan
Morgan

Reputation: 4131

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.

Upvotes: 2

Related Questions