Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

I've been in a SysAdmin/SRE type role for many years and I've used 200 status codes & non-200 codes as part of an automated site-check script for most of it. I've used the below script to automate scanning of 3000+ sites. (other optimizations exist, but this gets the job done quite nicely)

I like to do 2 layers of checks, (1) Is the site returning a 200? (2) Can the site return a specific file?

This script will send me an email alert if the site is not returning a 200 status code, but it's easy to daisy-chain other commands too.

Here's an example of (1):

#!/usr/local/bin/bash

INPUT="/usr/sync/urls.txt"

#DOWN="down.txt"

TODAY="$(date +'%Y-%m-%d_%R:%S')"

while read line ; do

status_code=$(/usr/local/bin/curl -o /dev/null --silent --head --write-out '%{http_code}\n' $line)

if [ $status_code -ne "200" ]

then

echo "$line is down since $TODAY" |mail -s Site_DOWN email@example.com

#echo "$line at $TODAY is DOWN" >> $DOWN #example to output to a file.

#You can add further actions here

fi

done </usr/sync/urls.txt



Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: