Briefing

Simple Bash Script for Automated Website Uptime Monitoring

hosting
by Anguishe ·

Run the provided bash script with cron to automatically check HTTP status codes and log results.

What to do now

Test the script locally and add the cron entry to automate uptime checks.

Summary

An author shares a minimal bash script that checks a website’s HTTP status code using curl and logs the result.

The core command uses curl -o /dev/null -s -w "%{http_code}" to return only the status code, which is then compared to 200 in a simple if statement that prints a check or cross symbol. The script defines CHECK and CROSS variables for readability and can be saved as uptime.sh, made executable with chmod +x, and tested manually with ./uptime.sh.

To automate the check, the author adds a cron entry “*/5 * * * * ~/uptime.sh >> ~/uptime.log 2>&1” that runs every five minutes, appends output to a log file, and redirects errors to stdout. The log can be monitored in real time with tail -f ~/uptime.log, confirming that cron is firing the script without manual intervention. The article also lists common HTTP status codes (200, 301/302, 404, 503, 000) and what action to take for each. A full copy‑paste version of the script and the cron line are provided for quick deployment. This approach gives developers a lightweight, scriptable way to keep an eye on site availability without relying on external monitoring services.

Key changes

  • Uses curl -o /dev/null -s -w "%{http_code}" to return only the HTTP status code
  • Defines CHECK and CROSS variables for clear output
  • Makes script executable with chmod +x and tests locally with ./uptime.sh
  • Adds cron entry "*/5 * * * * ~/uptime.sh >> ~/uptime.log 2>&1" to run every five minutes
  • Redirects stderr to stdout so errors are logged
  • Logs output to ~/uptime.log and can be watched with tail -f
  • Includes a table of common HTTP status codes and actions
  • Provides a full copy‑paste script and cron line for quick deployment

Affects

internal

Customer impact

Analyzing matches…

Ask about this story

Impact on an agency? Which customers? Compare historically Risks of waiting