2014-08-27 33 views
0

我有一個bash腳本,我使用ssh連接到另一臺服務器並在那裏運行一些命令。我發現一些網站的錯誤(Warning: no access to tty (Bad file descriptor). Thus no job control in this shell.)是一個友好的消息,但我的bash腳本得到「卡住」。出現此消息後,不會執行其他命令。其他論壇表示使用ssh -t壓制郵件,但它不適合我。我的代碼看起來是這樣的:如何擺脫「沒有訪問tty(壞文件描述符)」消息在bash中?

. 
. 
. 
stty -echo 
sshpass "pwd" ssh -o StrictHostKeyChecking=no [email protected] 'su -lc "rm -rf tmp"' 2>/dev/null 
stty echo 
. 
. 
. 

爲什麼我使用stty-echo的原因是因爲我需要用戶切換到root,密碼顯示在終端(我不想)上。在連接服務器(ip:1.1.1.1)上輸入root密碼後,我收到錯誤消息(Warning: no access to tty (Bad file descriptor). Thus no job control in this shell.)。

有什麼建議嗎?讓我知道是否需要進一步的解釋。謝謝! (我的bash的版本是GNU bash的版本,51年2月3日(1))

編輯

錯誤信息刪除2>/dev/null當我得到的是:

Warning: no access to tty (Bad file descriptor). 
Thus no job control in this shell. 
stty: standard input: Invalid argument 
+0

是否使用'-t'選項去除消息? – arco444 2014-08-27 15:46:30

+0

@ arco444已經嘗試過,並沒有擺脫問題 – Alias 2014-08-27 15:50:20

回答

0

而不是試圖隱藏密碼,我建議你通過添加你的SSH公鑰到目的地ID /服務器來使ssh連接成爲無密碼的。您需要必須爲您的密鑰提供密碼,並使用ssh-agent在需要時提供密碼。