2017-08-23 17 views
2

私はtest.shという名前の私のサーバー上でスクリプトを持っている:のssh(読み込みに問題)

#!/bin/bash 
read -p "Select an option [1-4]: " option 
echo "You have selected $option" 

私は手動でのsshを通してそれを実行すると、私はこれを参照してください。

[email protected]:~$ ssh [email protected] 
[email protected]'s password: 
[...] 
[email protected]:~# bash test.sh 
Select an option [1-4]: 48 
You have selected 48 

私はsshのリモートコマンドとしてそれを実行すると、私はこれを参照してください。

[email protected]:~$ ssh [email protected] 'bash test.sh' 
[email protected]'s password: 
48 
You have selected 48 

それはミスだから、私は、この出力に満足していますSelect an option [1-4]:プロンプト文字列と元のスクリプトから、私はtest.shにこのような対話型の文字列がたくさん含まれており、それらはすべて必要です。

私はそれがstderrに迅速だreadプリントはので、私は標準エラー出力が省略されている場合場合は、コマンドを次のようにスクリプトを起動しようとしたことを知っているが、出力はまだ同じまま:

ssh [email protected] 'bash test.sh >&2' 
ssh [email protected] 'bash test.sh' >&2 
ssh [email protected] 'bash test.sh 2>&1' 
ssh [email protected] 'bash test.sh' 2>&1 

なぜこれが起こっているとsshのリモートコマンドを期待通りに動かすには?

UPD

私はこれまでtest.sh変更されました:

#!/bin/bash 
echo Connected 
read -p "Select an option [1-4]: " option 
echo "You have selected $option" 

をが、出力はまだプロンプト文字列行方不明:あなたはssh-tオプションを使用する必要が

[email protected]:~$ ssh [email protected] 'bash test.sh' 
[email protected]'s password: 
Connected 
66 
You have selected 66 
+0

私は質問を更新しました。プロンプトはまだ表示されません。 – user619271

+0

行を印刷したいだけなら、 'echo'を使って行を印刷し、' read'を使って値を読み込みます。回避策です。 –

答えて

2

を擬似端末をsshセッションに割り当てます。

ssh -q -t [email protected] 'bash test.sh' 
+1

ありがとうございます。それは今働く。 – user619271