![휩테일을 사용한 체크리스트 - 여러 명령을 실행할 수 없는 이유는 무엇입니까?](https://linux55.com/image/10624/%ED%9C%A9%ED%85%8C%EC%9D%BC%EC%9D%84%20%EC%82%AC%EC%9A%A9%ED%95%9C%20%EC%B2%B4%ED%81%AC%EB%A6%AC%EC%8A%A4%ED%8A%B8%20-%20%EC%97%AC%EB%9F%AC%20%EB%AA%85%EB%A0%B9%EC%9D%84%20%EC%8B%A4%ED%96%89%ED%95%A0%20%EC%88%98%20%EC%97%86%EB%8A%94%20%EC%9D%B4%EC%9C%A0%EB%8A%94%20%EB%AC%B4%EC%97%87%EC%9E%85%EB%8B%88%EA%B9%8C%3F.png)
이 코드는 함수 아래 줄로 인해 첫 번째 일치에서만 실행됩니다.서비스 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
.