Check the availability of a web page using wget

To test the accessibility of a server, the ping command is used mostly. But it can happen, that a ping command is executed successfully, but the corresponding website is unreachable. To test this case, I have written a small script, that attempts with Wget, access the website.

#!/bin/bash
# Check site every 10 seconds, log failed connection attempts in siteuptime.txt
while true; do
echo "Checking site...";
/usr/bin/wget "Domain To Test" --timeout 1 -O - 2>/dev/null | grep "Website Searchstring " || echo "The site is down" | date --iso-8601=seconds >> /The/Output/File.txt;
sleep 1;
done

ME

Leave a Reply

Your email address will not be published. Required fields are marked *

Consent to the Privacy Policy

This site uses Akismet to reduce spam. Learn how your comment data is processed.