Color-Coded URL Status Checker in Bash: Enhanced Script for Fast Web Health Monitoring
Introduction: check-urls.sh – Fast, Visual URL Status Checks in Bash
Monitoring the health of multiple URLs is a common DevOps and web operations task. But staring at a wall of status codes can be tedious. What if you could instantly spot issues with color-coded output, all from a simple Bash script?
This post walks you through an improved Bash script that:
- Reads URLs from a file
- Checks their HTTP status using
curl
with a configurable timeout - Outputs results as
status_code url
, color-coded for instant readability
Body: Building a Smarter, More Readable URL Checker
check-urls.sh: The Enhanced Script
Below is the script. It’s concise, robust, and easy to integrate into any workflow.
|
|
check-urls.sh: Usage and Customization
- Input file: By default, the script reads from
/tmp/urls2
. You can specify another file as the first argument. - Timeout: The second argument sets the
curl
timeout (default: 5 seconds). - Output: Each line shows the HTTP status code (colored) followed by the URL.
Example
Suppose urls.txt
contains:
|
|
Run:
|
|
You’ll see:
- Green for 2xx (OK)
- Yellow for 3xx (redirects)
- Red for 4xx/5xx (errors)
- Gray for anything unexpected or unreachable
check-urls.sh: Why Color Matters
Color-coding status codes makes it trivial to spot issues in large lists:
- Green (2xx): All good
- Yellow (3xx): Redirects, worth checking
- Red (4xx/5xx): Broken or server errors, needs attention
- Gray: Timeouts, malformed responses, or unknown codes
This approach is especially useful in CI/CD pipelines, monitoring scripts, or manual audits.
Conclusion: Takeaways and Next Steps
A color-coded URL status checker in Bash is a simple yet powerful tool for web monitoring and troubleshooting. By leveraging curl
with timeouts and ANSI color codes, you get fast, readable feedback on the health of your endpoints.