⠛⠥⠝⠑⠽⠎⠥⠎ /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
<details class="ba bw2 mv2 pa2 b--light-gray">
    <summary class="fira mv1 dim fw7">http status checker</summary>
    <span><a download="bash-http-status-checker.functions.sh" class="link black bg-animate hover-bg-light-yellow pv3 ph3" href="./src/http-status-checker.functions.sh"><i
        class="icon icon-download"> </i> download</a> </span>        
    <div class="highlight"><pre class="chroma"><code class="language-bash" data-lang="bash"><span class="cp">#!/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