つばろぐ

主に C#, .NET, Azure の備忘録です。たまに日記。

curlでタイムアウトを設定するにはmax-timeオプションを使う

AZ-104 試験のために Microsoft Learn を進めている中で、Azure CLI仮想マシンを管理するテキストがあります。

learn.microsoft.com

そのテキストで Nginx をインストールした Azure VM に対して、curl を用いて Nginx をインストールしたことを確認するための Web ページが表示するコマンドが登場します。

curl -m 80 <パブリックIPアドレス>

curl-m オプションという見慣れないものがあり、気になったので調べてみました。

curl --help all | grep -- -m
     --create-file-mode <mode> File mode for created files
     --ftp-method <method> Control CWD usage
     --ftp-ssl-ccc-mode <active/passive> Set CCC mode
     --happy-eyeballs-timeout-ms <milliseconds> Time for IPv6 before trying IPv4
     --mail-auth <address> Originator address of the original email
     --mail-from <address> Mail from this address
     --mail-rcpt <address> Mail to this address
     --mail-rcpt-allowfails Allow RCPT TO command to fail for some recipients
 -M, --manual             Display the full manual
     --max-filesize <bytes> Maximum file size to download
     --max-redirs <num>   Maximum number of redirects allowed
 -m, --max-time <fractional seconds> Maximum time allowed for transfer
     --metalink           Process given URLs as metalink XML file
     --no-progress-meter  Do not show the progress meter
     --parallel-max <num> Maximum concurrency for parallel transfers
     --retry-max-time <seconds> Retry only within this period
     --tls-max <VERSION>  Set maximum allowed TLS version

-m, --max-time <fractional seconds> Maximum time allowed for transfer ということで、curl で実行するリクエストのタイムアウト(秒数)を設定するためのオプションのようです。

試しに 1秒でタイムアウトするように指定すると、すぐタイムアウトとなりました。

curl -m 1 8.8.8.8
curl: (28) Connection timed out after 1001 milliseconds

ちなみに grep コマンドでハイフンを含んだキーワードで調べたい場合は、キーワードの前に -- をつけるとよいということも学びました。