Shell Script Website Monitor
Lightweight automated website monitoring system using shell scripting — periodic HTTP checks, uptime logging, and failure alerts without requiring a full observability stack.

Lightweight automated website monitoring system using shell scripting — periodic HTTP checks, uptime logging, and failure alerts without requiring a full observability stack.

Problem
Before reaching for Prometheus and Grafana, you need to understand why monitoring exists. A freelance client needed basic uptime tracking for three web properties with zero infrastructure budget. The requirement: detect downtime within 5 minutes and send an alert.
Approach
Wrote a Bash script using curl to perform HTTP checks and capture response codes and response times.
Added logic to classify responses: 2xx (up), 4xx/5xx (application error), timeout (infrastructure failure).
Implemented structured logging of uptime/downtime events with timestamps to a flat log file.
Built a simple alert function supporting email notification and webhook (Slack-compatible) triggers.
Scheduled execution every 5 minutes using cron — no daemon, no dependencies.
Added a daily summary report script that aggregates uptime percentage from the log file.
Results
Code
Core HTTP check with response code classification and alert trigger.
check_site() {
local url=$1
local response
response=$(curl -s -o /dev/null -w "%{http_code} %{time_total}" \
--max-time 10 "$url")
local code time
read -r code time <<< "$response"
local ts
ts=$(date '+%Y-%m-%d %H:%M:%S')
if [[ $code =~ ^2 ]]; then
echo "$ts UP $url $code ${time}s" >> "$LOG_FILE"
else
echo "$ts DOWN $url $code ${time}s" >> "$LOG_FILE"
send_alert "$url" "$code"
fi
}Stack
Why it matters