2015-05-14 51 views
0

我有一個名爲ssadmin.sh的bash腳本,它管理另一個腳本sscounter.sh。 我正在使用面料執行ssadmin.sh面料掛在遠程bash腳本時

沒有pty=False

def ts1(): 
    with settings(warn_only=True): 
     run("chmod 775 %s" % 'ssadmin.sh') 
     run("%s start" % 'ssadmin.sh') 

sscounter.sh甚至無法啓動,但CMD不會被絞死:

[email protected]:~# /mithril/scripts/ss-bash/ssadmin.sh status 
ssserver not running 
sscounter.sh not running 

pty=False

def ts1(): 
    with settings(warn_only=True): 
     run("chmod 775 %s" % 'ssadmin.sh') 
     run("%s start" % 'ssadmin.sh', pty=False) 



[email protected]:~# /mithril/scripts/ss-bash/ssadmin.sh status 
ssserver not running 
10670 ?  S  0:00 /bin/bash /mithril/scripts/ss-bash/sscounter.sh 
sscounter.sh is running 

sscounter.sh開始,但cmd掛起:

E:\[Sync]\project\walbk\fab>fab ts1 
[192.168.1.181] Executing task 'ts1' 
[192.168.1.181] run: chmod 775 /mithril/scripts/ss-bash/ssadmin.sh 
[192.168.1.181] run: /mithril/scripts/ss-bash/ssadmin.sh start 
[192.168.1.181] out: stdin: is not a tty 
[192.168.1.181] out: 9915 ?  S  0:00 /bin/bash /mithril/scripts/ss-bash/sscounter.sh 
[192.168.1.181] out: sscounter.sh鍚姩涓?.. 
[192.168.1.181] out: 10670 ?  S  0:00 /bin/bash /mithril/scripts/ss-bash/sscounter.sh 
[192.168.1.181] out: sscounter.sh宸插惎鍔? 
[192.168.1.181] out:     (hang at here) 

1.爲什麼織物掛起?

2. fabric pty descriptionhttp://docs.fabfile.org/en/latest/usage/interactivity.html#echoes

pty is present to echo a user’s stdin,爲什麼sscounter.sh不會啓動時pty=True

+0

什麼是sscounter.sh? –

+0

@Padraic Cunningham它用於統計網絡流量https://github.com/hellofwy/ss-bash – Mithril

回答

1

我對你的代碼一目瞭然,因爲你不需要在sscounter.sh中打印任何東西,所以有一個快速解決懸掛問題的方法:將($DIR/sscounter.sh) &更改爲($DIR/sscounter.sh) >/dev/null 2>&1 &

當你沒有重定向stdout時,織物會等待它,並且因爲你的sscounter.sh不會退出織物似乎掛起。

如果遠程運行ssadmin.sh(沒有標準輸出重定向的版本),如下所示:ssh [email protected] 'bash ssadmin.sh',因爲同樣的原因它也會掛起。否則,如果你使用ssh -t [email protected] 'bash ssadmin.sh',它不會掛起。

我認爲使用織物pty=Truepty=False就像使用ssh有和沒有-t選項。

+0

它的作用像一個魅力!謝謝。但是我仍然想知道爲什麼當'pty = True'時'sscounter.sh'不能啓動? – Mithril

+0

@Mithril'sscounter.sh'首先啓動,但在會話終止後死亡。你可以使用'(nohup $ DIR/sscounter.sh)''而當'pty = True'' – WKPlus

+0

謝謝你的親切解釋! – Mithril