I see and use the nc
command a little bit, but every time I see it, I find out what it does, so make a note of it.
A command to start a simple client / server process.
Execute as follows to confirm communication as a client.
nc Target host (IP address, etc.) Port number
It is also possible to send the header to the destination port for processing. ʻEcho -en "GET / HTTP / 1.1 \ n \ n" | nc Target host (IP address, etc.) 80`
You can check whether the connection destination is running by the return value of nc. I want to use it when waiting for the destination container to start in Docker.
wait_for_port() {
local name="$1" host="$2" port="$3"
local j=0
while ! nc -z "$host" "$port" >/dev/null 2>&1 < /dev/null; do
j=$((j+1))
if [ $j -ge $TRY_LOOP ]; then
echo >&2 "$(date) - $host:$port still not reachable, giving up"
exit 1
fi
echo "$(date) - waiting for $name... $j/$TRY_LOOP"
sleep 5
done
}
-How to use the nc command -Check service connection with nc command -[8 usages to remember with the nc (netcat) command](https://orebibou.com/2015/11/ncnetcat%E3%82%B3%E3%83%9E%E3%83%B3%E3 % 83% 89% E3% 81% A7% E8% A6% 9A% E3% 81% 88% E3% 81% A6% E3% 81% 8A% E3% 81% 8D% E3% 81% 9F% E3% 81 % 84% E4% BD% BF% E3% 81% 84% E6% 96% B98% E5% 80% 8B /) -puckel / docker-airflow entrypoint.sh
Also articles that ssh in multiple stages
-Comfortable SSH commands with ~ / .ssh / config -Summary of how to use ssh
-W host:port
Requests that standard input and output on the client be forwarded to host
on port over the secure channel. Implies -N, -T, ExitOnForwardFailure and
ClearAllForwardings, though these can be overridden in the configuration
file or using -o command line options.
Recommended Posts