Skip to content

Instantly share code, notes, and snippets.

@akccakcctw
Created September 29, 2016 09:58
Show Gist options
  • Save akccakcctw/79ec31e8387c54a12d8aaa666e4b9b2b to your computer and use it in GitHub Desktop.
Save akccakcctw/79ec31e8387c54a12d8aaa666e4b9b2b to your computer and use it in GitHub Desktop.
檢查url狀態,並輸出為md檔
#!/bin/bash
# -----------------------
# |+++| version 1.0.0
# |+++| Rex Tsou
# |+++| 2016/09/29
# usage------------------
# $ ./checkurls.sh [file]
# -----------------------
echo '' >> url_status.md
echo `date` >> url_status.md
echo $1 >> url_status.md
echo '----' >> url_status.md
while read url
do
urlstatus=$(curl -o /dev/null --silent --head --write-out '%{http_code}\n' "$url")
if [[ $urlstatus =~ ^000$ ]] ; then #Regular Expression check http status code
echo "$url __"$urlstatus"__ No valid HTTP response <<<<<" >> url_status.md
elif [[ $urlstatus =~ ^3..$ ]] ; then
echo "$url __"$urlstatus"__ Redirection" >> url_status.md
elif [[ $urlstatus =~ ^4..$ ]] ; then
echo "$url __"$urlstatus"__ Client Error <<<<<" >> url_status.md
elif [[ $urlstatus =~ ^5..$ ]] ; then
echo "$url __"$urlstatus"__ Server Error <<<<<" >> url_status.md
else
echo "$url __"$urlstatus"__" >> url_status.md
fi
done < $1
echo '----' >> url_status.md
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment