Created
March 23, 2025 12:14
-
-
Save gayanhewa/c554e8065ef9b9b1dbe9da39ae1eefd3 to your computer and use it in GitHub Desktop.
Alternative script for checkonlinestatus.com for the terminal
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 | |
# ANSI Colors | |
RED="\033[0;31m" | |
GREEN="\033[0;32m" | |
YELLOW="\033[0;33m" | |
RESET="\033[0m" | |
# Function to check if a website is up | |
check_website() { | |
local url="$1" | |
local timeout=5 # Timeout in seconds | |
# Use curl to get HTTP status code | |
status_code=$(curl -o /dev/null -s -w "%{http_code}" --max-time $timeout "$url") | |
if [[ "$status_code" -ge 200 && "$status_code" -lt 400 ]]; then | |
echo -e "${GREEN}$url is UP (HTTP $status_code)${RESET}" | |
elif [[ "$status_code" -ge 400 ]]; then | |
echo -e "${RED}$url is DOWN (HTTP $status_code)${RESET}" | |
else | |
echo -e "${YELLOW}$url is unreachable or timeout occurred${RESET}" | |
fi | |
} | |
# Main script execution | |
if [[ -z "$1" ]]; then | |
echo "Usage: $0 <URL>" | |
exit 1 | |
fi | |
check_website "$1" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment