[Bash] HTTP ステータスコード 200 を返す URL をリストアップする Shell Script

HTTP ステータスコード 200 を返す URL をリストアップする bash で動く Shell Script をご紹介します。

array=();
 
for (( i = 1 ; i < 10 ; i++ ))
do
  url=http://example.com/$i/;
  http_code=`curl -LI $url -o /dev/null -w '%{http_code}' -s`;
  if [ $http_code = 200 ]; then
    array+=($url);
  fi
done
 
for el in $array; do
  echo $el;
done

サッと確認したいときに使うといいと思います。