curl
毎回調べるオプション
ファイル保存する: -O
リダイレクトフォローする: -L
ヘッダーを表示する: -I --head
ヘッダーを指定する: -H 'Authorization:Bearer abc'
出力先を指定: -o /dev/null
プログレスバーを消す: -s
通信エラー時にexit codeに反映: -f
curlrcを無視: -q
ステータスコードを表示: -w '%{http_code}\n'
詳しくは公式参照
https://curl.se/docs/manpage.html
cookbook
標準出力と標準エラーを消す
code:bash
$ curl -q https://site/ > /dev/null 2>&1
$ curl -q https://site/ -s -o /dev/null
ステータスコードを確認する
code:bash
$ curl -q https://site/ -w '%{http_code}\n' > /dev/null 2>&1
$ curl -q https://site/ -w '%{http_code}\n' -s -o /dev/null
exit codeを確認する
code:bash
$ curl -q https://site/ -f > /dev/null 2>&1 || echo $?
$ curl -q https://site/ -f -s -o /dev/null || echo $?
ref: https://superuser.com/a/727996
疎通待ちをする、 -w でデバッグ表示付き(Makefile等)
code:bash
/bin/echo -n "Waiting for HTTPS status 200 ..."; while ! curl -q https://site/ -w '%{http_code}\n' -f -s -o /dev/null; do /bin/echo -n "."; sleep 1; done; /bin/echo "ok"
code:console
Waiting for HTTPS status 200 ...502
.502
.502
.502
.200
ok
ヘッダーを指定する
code:console
$ curl -H 'Authorization:Bearer abc' http://example.com