Skip to content

Instantly share code, notes, and snippets.

@karpstrucking
Created August 25, 2015 17:02
Show Gist options
  • Save karpstrucking/6747ee220e0415731e52 to your computer and use it in GitHub Desktop.
Save karpstrucking/6747ee220e0415731e52 to your computer and use it in GitHub Desktop.
Example of a simple uptime checking script using sites in InfiniteWP database
#!/bin/bash
# Database configuration
DBNAME=""
DBUSER=""
DBPASS=""
# Email configuration
TO=""
FROM=""
SUBJECT=""
# Processing
QUERY="SELECT URL FROM iwp_sites ORDER BY RAND()"
SITES=$( echo $QUERY | mysql $DBNAME -u $DBUSER -p$DBPASS --skip-column-names )
for SITE in $SITES; do
CODE=$( curl -iskL $SITE | grep "HTTP/" | tail -n 1 | cut -d$' ' -f2 )
if [ "$CODE" -ge 400 ] || [ "$CODE" -eq 0 ]; then
echo "$SITE appears to be offline" | mail -S from="$FROM" -s "$SUBJECT" "$TO"
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment