[LINUX] nc command memorandum

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.

Overview

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`

Check if the connection destination is alive

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
}

Link Collection

-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

nc command memorandum
Command memorandum
Command memorandum
Memorandum conda command
setuptools command memorandum
memorandum of vi command
Linux basic command memorandum
Linux command memorandum [for beginners]
Introduction to vi command (memorandum)
Process confirmation command ps option memorandum
Matplotlib memorandum
linux memorandum
Linux command # 4
jinja2 memorandum
Django memorandum
Python Memorandum 2
nkf command
command prompt
plotly memorandum
Slackbot memorandum (1)
vim command
multiprocessing memorandum
Memorandum MetaTrader 5
[Linux/LPIC] Memorandum
ShellScript memorandum
pip memorandum
sed command
Python memorandum
Linux command # 5
grep command
pydoc memorandum
command memo
python memorandum
Pandas memorandum
python memorandum
DjangoGirls memorandum
top command
Command memo
Python memorandum
pandas memorandum
python memorandum
mv command
Python memorandum
seq command
[Linux command] A memorandum of frequently used commands