Cache testing with curl and grep


Just wrote a quick shell script to test web server cache and background updating by displaying header output from curl.
Don’t have time to write a description here, just having the script for reference.

<br />
#!/bin/bash<br />
#<br />
# 2016-05-06 20:22:35<br />
# myrveln@gmail.com<br />
#<br />
# Test cache functionality<br />
#</p>
<p>usage(){<br />
    echo &quot;Usage: $0 [ http://domain.com ] [ sleeptimer ]&quot;<br />
    exit 1<br />
}</p>
<p># We need two parameters<br />
if [[ $# -lt 2 ]]; then<br />
    usage<br />
    exit 1<br />
# We want only full urls<br />
elif [[ ! $1 == http*://* ]]; then<br />
    usage<br />
    exit 1<br />
# We want only numeric sleeptimer<br />
elif [[ -z &quot;${2##*[!0-9]*}&quot; ]]; then<br />
    usage<br />
    exit 1<br />
fi</p>
<p>echo &quot;TERMINATE THE SCRIPT WITH CTRL+C&quot;<br />
echo &quot;----------------------&quot;</p>
<p>while true<br />
do<br />
    START_TIME=&quot;$(date +%s%N)&quot;<br />
    OUTPUT=$(curl -o /dev/null -D - -s ${1} | grep 'Age:\|Warning:\|X-Cache\|Via:\|Expires:\|X-RateLimit-Remaining:' | sort)<br />
    ELAPSED_TIME=&quot;$((($(date +%s%N) - ${START_TIME})/1000000))&quot;<br />
    echo &quot;${OUTPUT}&quot;<br />
    echo &quot;Elapsed time: ${ELAPSED_TIME} ms&quot;<br />
    echo &quot;----------------------&quot;<br />
    sleep ${2}<br />
done<br />

Comments

comments