Explanation:
Shebang:
#!/bin/bash
specifies that this script should be interpreted using the Bash shell.check_website Function: Uses
curl
to send an HTTP request (-s
for silent,-o /dev/null
to suppress output,-w "%{http_code}"
to print HTTP status code) to the specified website ($SITE
). The HTTP status code ($STATUS_CODE
) is then checked:- If
STATUS_CODE
is200
, the website is considered UP. - Otherwise, it's considered DOWN.
- If
WEBSITES Array: Contains a list of websites (
http://example.com
,https://google.com
,https://github.com
) that you want to monitor. Add or remove websites as needed.Loop: Iterates through each website in the
WEBSITES
array, callingcheck_website
function for each.
Usage:
- Save this script to a file, e.g.,
check_website_uptime.sh
. - Make it executable with
chmod +x check_website_uptime.sh
. - Run it with
./check_website_uptime.sh
.
Notes:
Customization: Modify the
WEBSITES
array to include the URLs of the websites you want to monitor.Error Handling: This script assumes basic error handling. You may want to add more robust error checking and reporting based on your specific requirements.
Security: Be mindful of rate limiting and impact on the monitored websites. Use appropriate intervals between checks to avoid overwhelming the servers.
This script provides a basic framework for checking the uptime status of websites using HTTP status codes. Depending on your needs, you can enhance it with features like email alerts, logging, or integration with monitoring systems for more comprehensive website monitoring.
0 Comments