7

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

2 Answers 2

7

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.

1
  • note: commands with space needs to include \ for space instead as it removes all spaces
    – pg2455
    Mar 19, 2019 at 20:10
2

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.