このコードは、関数の下の行のために最初の一致でのみ実行されます。サービス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
コードでは、stdin
fileの値はtoとto(in、および)のresults
両方に割り当てられます。最初のループで未読の内容はすべて食べられます。while read ...
ssh
s1
s2
s3
ssh
read
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
。