ホイップテールを使用したチェックリスト - 複数のコマンドを実行できないのはなぜですか?

ホイップテールを使用したチェックリスト - 複数のコマンドを実行できないのはなぜですか?

このコードは、関数の下の行のために最初の一致でのみ実行されます。サービスhttpdが起動しますただし、すべてのssh ...行を削除すると、すべての機能のエコーが表示されます。誰かが私に何が起こっているのかを説明することができ、どのように使用できるかについての解決策があるかもしれません。

#!/bin/bash
 function s1 {
        echo "running 1 "
        ssh user@server_1_IP service httpd start
}
    function s2 {
        echo "running 2"
        ssh user@server_2_IP service httpd start
} 
function s3 {
        echo "running 3"
        ssh user@server_3_IP service httpd start
}
whiptail --title "Test" --checklist --separate-output "Choose:" 20 78 15 \
"Server1" "" on \
"Server2" "" on \
"Server3" "" on 2>results

while read choice  
do
        case $choice in
                Server1) s1
                ;;
                Server2) s2
                ;;
                Server3) s3
                ;;
                *)
                ;;
        esac
done < results

ベストアンサー1

コードでは、stdinfileの値はtoとto(in、および)のresults両方に割り当てられます。最初のループで未読の内容はすべて食べられます。while read ...sshs1s2s3sshread

stdin後でSSHとして使用するために繰り返す前に保存してください。

exec {stdin}<&0
while read choice  
do
        case $choice in
                Server1) s1 <&$stdin ;;
                Server2) s2 <&$stdin ;;
                Server3) s3 <&$stdin ;;
        esac
done < results

< /dev/nullまたはstdinが必要ない場合ssh

おすすめ記事