Created
August 25, 2015 17:02
-
-
Save karpstrucking/6747ee220e0415731e52 to your computer and use it in GitHub Desktop.
Example of a simple uptime checking script using sites in InfiniteWP database
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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