⠛⠥⠝⠑⠽⠎⠥⠎ /home/asguneysu

Simple HTTP Status Checker CLI with Shell

by Ahmed Şeref Güneysu

usage

$ source http-status-checker.functions.sh && get-links example.com | http-check-bulk
  200  http://www.iana.org/domains/example
http status checker download
#!/bin/bash

function http-status-check {
	# export TERM=xterm-color
	# export GREP_OPTIONS='--color=auto' GREP_COLOR='1;32'
	# export CLICOLOR=1
	# export LSCOLORS=ExFxCxDxBxegedabagacad
<span class="nv">NORMAL</span><span class="o">=</span><span class="sb">`</span><span class="nb">echo</span> -e <span class="s1">&#39;\033[0m&#39;</span><span class="sb">`</span>
<span class="nv">RED</span><span class="o">=</span><span class="sb">`</span><span class="nb">echo</span> -e <span class="s1">&#39;\033[31m&#39;</span><span class="sb">`</span>
<span class="nv">GREEN</span><span class="o">=</span><span class="sb">`</span><span class="nb">echo</span> -e <span class="s1">&#39;\033[0;32m&#39;</span><span class="sb">`</span>
<span class="nv">LGREEN</span><span class="o">=</span><span class="sb">`</span><span class="nb">echo</span> -e <span class="s1">&#39;\033[1;32m&#39;</span><span class="sb">`</span>
<span class="nv">BLUE</span><span class="o">=</span><span class="sb">`</span><span class="nb">echo</span> -e <span class="s1">&#39;\033[0;34m&#39;</span><span class="sb">`</span>
<span class="nv">LBLUE</span><span class="o">=</span><span class="sb">`</span><span class="nb">echo</span> -e <span class="s1">&#39;\033[1;34m&#39;</span><span class="sb">`</span>
<span class="nv">YELLOW</span><span class="o">=</span><span class="sb">`</span><span class="nb">echo</span> -e <span class="s1">&#39;\033[0;33m&#39;</span><span class="sb">`</span>


<span class="c1"># uri $1</span>
<span class="nv">URL</span><span class="o">=</span><span class="nv">$1</span>
<span class="nv">STATUS</span><span class="o">=</span><span class="s2">&#34;</span><span class="k">$(</span>curl --connect-timeout <span class="m">1</span> -sL -w <span class="s2">&#34;%{http_code}\\n&#34;</span> <span class="s2">&#34;</span><span class="si">${</span><span class="nv">URL</span><span class="si">}</span><span class="s2">&#34;</span> -o /dev/null<span class="k">)</span><span class="s2">&#34;</span>
<span class="k">if</span> <span class="o">[[</span> <span class="nv">$STATUS</span> -ne <span class="m">200</span> <span class="o">]]</span>
    <span class="k">then</span>
        <span class="nb">echo</span> <span class="s2">&#34; </span><span class="si">${</span><span class="nv">YELLOW</span><span class="si">}</span><span class="s2"> </span><span class="nv">$STATUS</span><span class="s2"> </span><span class="si">${</span><span class="nv">RED</span><span class="si">}</span><span class="s2"> </span><span class="nv">$URL</span><span class="si">${</span><span class="nv">NORMAL</span><span class="si">}</span><span class="s2"> &#34;</span>
    <span class="k">else</span>
        <span class="nb">echo</span> <span class="s2">&#34; </span><span class="si">${</span><span class="nv">YELLOW</span><span class="si">}</span><span class="s2"> </span><span class="nv">$STATUS</span><span class="s2"> </span><span class="si">${</span><span class="nv">BLUE</span><span class="si">}</span><span class="s2"> </span><span class="nv">$URL</span><span class="s2"> </span><span class="si">${</span><span class="nv">NORMAL</span><span class="si">}</span><span class="s2">&#34;</span>
<span class="k">fi</span>

}

function get-links () { wget $1 -O - 2>/dev/null | grep -oP 'href="\Khttp:.+?"' | sed 's/"//' | sort }

function http-check-bulk () { command=$1

<span class="k">while</span> <span class="nb">read</span> p<span class="p">;</span> <span class="k">do</span>
    http-status-check <span class="nv">$p</span>
<span class="k">done</span> &lt;/dev/stdin

}

demo

DMCA.com Protection Status