Automating Server Monitoring with Bash and Cron

Published: May 20, 2026 | 6 min read | By Talha Arshad

One of the key requirements of the ICT171 assignment is to produce a script with verifiable output – something that runs on the server and produces visible results. I decided to build a live server status page that updates automatically every 5 minutes.

The Goal

Create a webpage (/status.html) that shows real‑time system metrics: uptime, memory usage, disk space, load average, and active network connections. The page must be accessible to anyone visiting https://talhatechub.online/status.html.

The Bash Script

Here is the complete script (/home/ubuntu/scripts/server_status.sh):

#!/bin/bash
OUTPUT_FILE="/var/www/html/status.html"

cat > $OUTPUT_FILE << 'EOF'

<html>
<head>
<meta charset="UTF-8">
<title>Server Status - Talha's Cloud</title>
<style>
body { font-family: monospace; background: #f0f0f0; }
pre { background: #ffffff; padding: 20px; border-radius: 8px; }
</style>
</head>
<body>
<h1>Talha's Cloud Server - Live Status</h1>
<pre>
Uptime:        $(uptime)
Memory usage:  $(free -h | grep Mem)
Disk usage:    $(df -h / | tail -1)
Load average:  $(cat /proc/loadavg)
Open ports:    $(ss -tun | wc -l) connections
Last updated:  $(date)
</pre>
<p><a href="/">Back to homepage</a></p>
</body>
</html>
EOF
    

The script does three things:

Automating with Cron

Running the script manually is not useful. I used cron, a time‑based job scheduler in Linux, to execute the script every 5 minutes.

The cron job entry:

*/5 * * * * /home/ubuntu/scripts/server_status.sh

I added it with:

(crontab -l 2>/dev/null; echo "*/5 * * * * /home/ubuntu/scripts/server_status.sh") | crontab -

Verifiable Output

Any visitor can open https://talhatechub.online/status.html and see the current server health. This satisfies the rubric's requirement for "script verifiable output" – the output is clearly visible on the public internet.

💡 Why this is creative and useful:
- Provides real‑time insight into server performance.
- Fully automated – no manual intervention after setup.
- Integrates with the main website (the status page is linked from the homepage).
- Demonstrates bash scripting, cron scheduling, and web integration.

Extending the Idea

This pattern can be extended to monitor multiple servers, send email alerts if disk space is low, or generate historical graphs. For this project, the simple status page is sufficient and clearly meets the learning outcomes.