• Image Checker

I threw this bit of code together today to help monitor some disappearing pictures for one of my clients in an ongoing disappearing pictures issue. It’s pretty limited in its capabilities in this version, but this is not the only time I had to monitor such a situation. Maybe someone else will stumble upon this little toy and it’ll make their day a little bit easier:

#Finds images within a given URL and checks for the existence of those images
#Version 1.0.0 by Jason M Potter cpguy.com


##Begin Code
function logger {
awk '{print "[" strftime("%F %H:%M:%S") "]",$0;}'

echo "Checking images on $URL..."|logger

#curl opts key:

<h1>-s, --silent : no progress indicators</h1>

<h1>-f, --fail : exit nonzero on failure</h1>

<h1>-r, --range : retrieve byte range</h1>

<h1>-L, --Location : follow redirects</h1>

<h1>-k, --insecure : skip SSL errors</h1>

<h1>-o, --output : write to filename</h1>

curl -skL $URL | awk '
/img src=/{
URL=gensub(/.<em>img src="([^"]+)".</em>/,"\1","g",$0)
e="curl -skLfr 0-0 -o /dev/null "URL" 2>&1 && echo EXISTS || echo MISSING"
e|getline x
print x,URL
} END {
if (NR==0) print "No Response from '

Sample Output

[2018-05-31 22:52:20] Checking images on cpguy.com...
[2018-05-31 22:52:21] EXISTS http://cpguy.com/wp-content/uploads/2018/05/cropped-cpguy.com-header.png

[2018-05-31 22:55:27] Checking images on cpguy.com...
[2018-05-31 22:55:28] MISSING http://cpguy.com/wp-content/uploads/2018/05/cropped-cpguy.com-header.png