Warning: Undefined variable $post_id in /home/cpguy/public_html/wp-content/themes/nucleare-wpcom/content-page.php on line 15

• 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:

[cce_bash]
#!/bin/bash
#Finds images within a given URL and checks for the existence of those images
#Version 1.0.0 by Jason M Potter cpguy.com

URL=”cpguy.com”

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

echo “Checking images on $URL…”|logger

#curl opts key:

-s, –silent : no progress indicators

-f, –fail : exit nonzero on failure

-r, –range : retrieve byte range

-L, –Location : follow redirects

-k, –insecure : skip SSL errors

-o, –output : write to filename

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

Sample Output

[cce lang=”bash” line_numbers=”0″]
[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
[/cce]