π DevSecOps Journey β Day 11

Building a Website Health Monitoring & Log Archival Automation with Shell Scripting
β¨ From basic scripting to production-style automation
Today, I worked on a hands-on automation project that closely mirrors how monitoring and log management are handled in real DevOps and DevSecOps environments.
The focus was on:
π Website health monitoring
π§Ύ Structured logging
π Log archival & cleanup automation
π Project 1: Website Health Monitoring Script
The goal of this script is to continuously monitor a websiteβs availability and performance and store the data in daily logs.
π What the Script Does
Takes a target URL
Creates a dedicated log directory
Generates date-based log files
Makes an HTTP request using
curlExtracts:
β HTTP status code
β± Response time
Logs everything with a timestamp into a daily log file
This approach is commonly used in:
Uptime monitoring
Synthetic health checks
SRE probes
Custom monitoring agents
π Key Concepts Used
Shell scripting fundamentals
Variables & directory management
curlfor HTTP/API callsParsing output using
awkTimestamp generation
Output redirection (
>>)
π§ͺ Website Health Script
#!/bin/bash
URL="https://github.com"
LOG_DIR="$HOME/website_health_log"
mkdir -p "$LOG_DIR"
TODAY=$(date +"%Y-%m-%d")
LOG_FILE="$LOG_DIR/health_log_$TODAY.log"
response=$(curl -o /dev/null -s -A "Mozilla/5.0" -w "%{http_code} %{time_total}" "$URL")
status_code=$(echo "$response" | awk '{ print $1 }')
response_time=$(echo "$response" | awk '{ print $2 }')
timestamp=$(date +"%Y-%m-%d %H:%M:%S")
echo "$timestamp | status : $status_code | response : ${response_time}s" >> "$LOG_FILE"
π Why this matters:
This simulates how real monitoring systems capture availability and performance metrics in production.
π Project 2: Log Archival & Cleanup Automation
Monitoring generates logs continuously. Without cleanup, storage can quickly grow out of control.
To solve this, I created a log archival script.
π¦ What the Archival Script Does
Identifies yesterdayβs log file
Compresses it into a
.tar.gzarchiveDeletes the original log file
Maintains an
archive_history.logPrevents duplicate archiving
This mirrors real log retention strategies used in production systems.
π§ͺ Log Archival Script
#!/bin/bash
LOG_DIR="$HOME/website_health_logs"
YESTERDAY=$(date -d "yesterday" +"%Y-%m-%d")
YESTERDAY_LOG="$LOG_DIR/health_log_$YESTERDAY.log"
YESTERDAY_ARCHIVE="$LOG_DIR/health_log_$YESTERDAY.tar.gz"
ARCHIVE_HISTORY="$LOG_DIR/archive_history.log"
if [ -f "$YESTERDAY_LOG" ] && [ ! -f "$YESTERDAY_ARCHIVE" ]; then
tar -czf "$YESTERDAY_ARCHIVE" "$YESTERDAY_LOG"
rm "$YESTERDAY_LOG"
echo "$(date) | Archived $YESTERDAY_LOG" >> "$ARCHIVE_HISTORY"
else
echo "$(date) | Nothing to archive or already archived" >> "$ARCHIVE_HISTORY"
fi
π Why Log Archival Matters
Proper log lifecycle management helps with:
πΎ Disk space optimization
π Audit & compliance readiness
π§Ή Clean operational environments
βοΈ Predictable automation behavior
π― Why This Project Matters for DevOps / DevSecOps
This mini-project combines multiple production-grade practices:
π Automation over manual monitoring
π Observability fundamentals
π Log rotation & archival
π‘ Traceability via history logs
βοΈ Idempotent scripting logic
These are the same patterns used in:
CI/CD pipelines
Cron jobs
Monitoring agents
SRE tooling
Security & compliance workflows
β Day 11 Summary
Today, I built:
π A website health monitoring script
π§Ύ Daily structured logs with timestamps
π¦ Automated log archival & cleanup
π Archival history tracking
This hands-on project strengthened my understanding of automation, monitoring, and operational reliability, which are core to modern DevSecOps workflows.
π Source Code:
π GitHub: https://github.com/Jysh06/website_health_logger
π Final Thoughts
You donβt need complex tools to start learning DevOps.
Start small.
Understand deeply.
Automate everything. π₯
If youβre also learning Linux / DevOps / SRE, feel free to connect and share feedback π
Happy Learning! π




