Skip to content

Instantly share code, notes, and snippets.

@htnosm
Last active June 25, 2019 06:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save htnosm/a7ec703054dcae445e205caeb5c0f5d2 to your computer and use it in GitHub Desktop.
Save htnosm/a7ec703054dcae445e205caeb5c0f5d2 to your computer and use it in GitHub Desktop.
URL Check of GET

Usage

Usage: ./check-url.sh "target csv"

Setting

cat <<_EOF > target.csv
# url,protocol{http/https/both},memo
example.com,both,TEST
sub.example.com,https
_EOF
#!/bin/bash
_CSV=${1}
_LOGDIR="output"
function USAGE() {
cat <<_EOF
Usage: ${0} "target csv"
_EOF
}
if [ ! -f "${_CSV}" ]; then
USAGE ; exit 1
fi
cd $(cd $(dirname ${0}) && pwd)
[ -d "${_LOGDIR}" ] || mkdir -p "${_LOGDIR}"
_RUNDATE="$(date +'%Y%m%d_%H%M%S')"
_LOG=${_LOGDIR}/$(basename ${0} .sh).$(basename ${_CSV} .csv).${_RUNDATE}.log
_SUMMARY=${_LOGDIR}/$(basename ${0} .sh).$(basename ${_CSV} .csv).${_RUNDATE}.summary.log
for i in $(grep -v -e '^#' -e '^$' "${_CSV}" | sed -e 's% %%g')
do
_URL=$(echo ${i} | awk -F ',' '{print $1}')
_PROTOCOL=$(echo ${i} | awk -F ',' '{print $2}')
_MEMO=$(echo ${i} | awk -F ',' '{print $3}')
if [ -z "${_MEMO}" ]; then
echo "# ${_URL}" | tee -a ${_LOG}
else
echo "# ${_URL} (${_MEMO})" | tee -a ${_LOG}
fi
case "${_PROTOCOL}" in
"both" ) _PROTOCOLs=("http" "https") ;;
"http"|"https" ) _PROTOCOLs="${_PROTOCOL}" ;;
* )
unset _PROTOCOLs
echo "Invalid value: ${_PROTOCOL}"
;;
esac
for j in ${_PROTOCOLs[@]}
do
echo "## ${j}" | tee -a ${_LOG}
set -x
(
curl -iLSsf -m 5 "${j}://${_URL}"
) 2>&1 | tee -a ${_LOG}
set +x
echo '' | tee -a ${_LOG}
sleep 1
done
done
cat <<_EOF
--------------------------------------------------------------------------------
Result Summay
--------------------------------------------------------------------------------
$(grep -a -e '^#' -e '^curl' -e '^HTTP' "${_LOG}" | tee "${_SUMMARY}")
--------------------------------------------------------------------------------
_EOF
gzip "${_LOG}"
cat <<_EOF
Output File:
$(ls -l ${_LOGDIR}/$(basename ${0} .sh).$(basename ${_CSV} .csv).${_RUNDATE}*)
--------------------------------------------------------------------------------
_EOF
exit
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment