나는 다음과 같은 정확한 코드를 가지고 있습니다.
#!/bin/bash
gtimeout(){
if type -f gtimeout &> /dev/null; then
command gtimeout "$@"
else
timeout "$@"
fi
}
export -f gtimeout;
on_first_match(){
local pattern="$1" # The pattern to search for
while IFS= read -r line; do
if [[ "$line" == *"$pattern"* ]]; then
exit 0
fi
done
}
export -f on_first_match
write_to_server(){
echo -e "$?" | nc 0.0.0.0 3333
}
export -f write_to_server
(
set +e;
sleep 2;
(
gtimeout 15 docker logs -f rabbitmq-node1 | on_first_match 'Starting listener on';
write_to_server
) &
(
gtimeout 15 docker logs -f mongodb-node1 | on_first_match 'waiting for connections';
write_to_server
) &
(
gtimeout 15 docker logs -f elasticsearch-node1 | on_first_match 'started';
write_to_server
) &
(
gtimeout 15 docker logs -f rabbitmq-node2 | on_first_match 'Starting listener on';
write_to_server
) &
(
gtimeout 15 docker logs -f mongodb-node2 | on_first_match 'waiting for connections';
write_to_server
) &
(
gtimeout 15 docker logs -f elasticsearch-node2 | on_first_match 'started';
write_to_server
) &
(
gtimeout 15 docker logs -f rabbitmq-node3 | on_first_match 'Starting listener on';
write_to_server
) &
(
gtimeout 15 docker logs -f mongodb-node3 | on_first_match 'waiting for connections';
write_to_server
) &
(
gtimeout 15 docker logs -f elasticsearch-node3 | on_first_match 'started';
write_to_server
) &
) &
gtimeout 30 nc -k -l 3333 | while IFS= read -r line; do
echo "Received: $line";
done
내가 얻는 결과는 다음과 같습니다.
Error response from daemon: No such container: mongodb-node1
Error response from daemon: No such container: rabbitmq-node2
Error response from daemon: No such container: rabbitmq-node1
Error response from daemon: No such container: elasticsearch-node2
Error response from daemon: No such container: elasticsearch-node1
Error response from daemon: No such container: mongodb-node2
Error response from daemon: No such container: mongodb-node3
Error response from daemon: No such container: rabbitmq-node3
Error response from daemon: No such container: elasticsearch-node3
Received: 0
Received: 0
Received: 0
Received: 0
Received: 0
(5줄만 수신되고 때로는 4줄, 때로는 6줄이 수신되지만 예상대로 9줄은 수신되지 않음)
하지만 나는 이것을 기대한다:
Error response from daemon: No such container: mongodb-node1
Error response from daemon: No such container: rabbitmq-node2
Error response from daemon: No such container: rabbitmq-node1
Error response from daemon: No such container: elasticsearch-node2
Error response from daemon: No such container: elasticsearch-node1
Error response from daemon: No such container: mongodb-node2
Error response from daemon: No such container: mongodb-node3
Error response from daemon: No such container: rabbitmq-node3
Error response from daemon: No such container: elasticsearch-node3
Received: 0
Received: 0
Received: 0
Received: 0
Received: 0
Received: 0
Received: 0
Received: 0
Received: 0
9개의 수신 라인이 있습니다.
무슨 일인지 아는 사람 있나요? (소켓 대신 mkfifo로 코드를 전환하면 동일한 동작이 발생합니다).