LoginSignup
7
5

More than 3 years have passed since last update.

curlでステータスコードを取得する

Last updated at Posted at 2019-06-14

とあるURLのステータスコード

至ってシンプルに、200とか、404とか取得したいなー。と。

curl -LI [URL] -o /dev/null -w '%{http_code}\n' -s
で取得できまする。

e.g.
curl -LI https://www.favy.jp/hogehoge -o /dev/null -w '%{http_code}\n' -s

とある複数URLのステータスチェック

curl -LI [URL1] -o /dev/null -w '%{http_code}\n' -s >> tmp.txt
を複数行に渡って書いたシェルファイルを作って実行しよう。

vim test.sh
test.sh
curl -LI https://www.favy.jp/hogehoge -o /dev/null -w '%{http_code}\n' -s >> tmp.txt
curl -LI https://www.favy.jp/hogehoge2 -o /dev/null -w '%{http_code}\n' -s >> tmp.txt
curl -LI https://www.favy.jp/hogehoge3 -o /dev/null -w '%{http_code}\n' -s >> tmp.txt
curl -LI https://www.favy.jp/hogehoge4 -o /dev/null -w '%{http_code}\n' -s >> tmp.txt
・
・

チェックはこれで。

less +F tmp.txt
(tail -f tmp.txt)

※あまり大量にやっちゃ駄目よ。

7
5
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
7
5