πŸš€ Creating a Dynamic MOTD Dashboard for Ubuntu EC2 with Logs, AWS Metadata & Alerts

🧭 Introduction

When you SSH into your Linux server, you’re greeted with a simple Message of the Day (MOTD). But what if it could show real-time disk alerts, AWS metadata, failed services, and log summaries right away?

In this blog, I’ll show how I progressively customized /etc/update-motd.d/ to build a DevOps-style MOTD dashboard for my Ubuntu EC2 instance running MKCloudAI.


πŸͺœ Step 1: Start Simple β€” Basic Banner & Uptime

🧱 Goal

Display a welcome message and key server details.

πŸ“„ Script: 99-custom

#!/bin/bash

echo ""
echo "╔══════════════════════════════════════╗"
echo "β•‘ πŸš€ Welcome to MKCloudAI Server β•‘"
echo "╠══════════════════════════════════════╣"
echo "β•‘ πŸ”’ Secured Ubuntu Server - DevOps β•‘"
echo "β•‘ πŸ•’ Uptime: $(uptime -p) β•‘"
echo "β•‘ πŸ’‘ Tip: Keep your system updated! β•‘"
echo "β•šβ•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•"
echo ""
echo "🌐 Hostname: $(hostname)"
echo "πŸ•’ Uptime: $(uptime -p)"

πŸ”§ Place this file in /etc/update-motd.d/99-custom and make it executable with chmod +x.


πŸͺœ Step 2: Add Disk and Memory Usage

πŸ’Ύ Disk + 🧠 RAM

echo "πŸ’Ύ Disk Usage: $(df -h / | awk 'NR==2 {print $5 " used"}')"
echo "🧠 Memory Usage: $(free -m | awk '/Mem:/ {printf("%.1f%% used\n", $3/$2*100)}')"

Now it starts to feel useful β€” I can spot memory or disk issues the moment I log in.


πŸͺœ Step 3: Add 🚨 Disk Usage Alert

🚨 Goal

Trigger a warning if disk usage exceeds 80%.

disk_usage=$(df / | awk 'NR==2 {gsub("%","",$5); print $5}')
if [ "$disk_usage" -ge 80 ]; then
echo "🚨 ALERT: Root disk usage is above 80% ($disk_usage%)"
fi

Now I don’t need to manually run df -h β€” it warns me instantly.


πŸͺœ Step 4: Add ☁️ AWS EC2 Metadata

☁️ Add Instance Info Using Instance Metadata Service

meta_base="http://169.254.169.254/latest/meta-data"
instance_id=$(curl -s ${meta_base}/instance-id)
instance_type=$(curl -s ${meta_base}/instance-type)
region=$(curl -s ${meta_base}/placement/availability-zone | sed 's/[a-z]$//')

echo "☁️ AWS Instance ID: $instance_id"
echo "☁️ AWS Type: $instance_type | Region: $region"

This helps identify which EC2 instance I’m on, especially when working across multiple environments.


πŸͺœ Step 5: Add ❌ Failed System Services

failed_services=$(systemctl --failed --no-legend)
if [ -n "$failed_services" ]; then
echo "❌ Failed Services:"
echo "$failed_services" | awk '{print " β†’ " $1 " (" $2 ")"}'
fi

This was a game-changer β€” no more missing broken services like postfix, nginx, or docker.


πŸͺœ Step 6: Add πŸ“… Cron Job Preview

echo "πŸ“… Upcoming Cron Jobs:"
(crontab -l 2>/dev/null; sudo crontab -l 2>/dev/null) | grep -v '^#' | awk 'NF' | while read -r job; do
echo " β†’ $job"
done

Now I can double-check scheduled jobs at a glance after each login.


πŸͺœ Step 7: Add πŸ“œ Meaningful Log Summaries

Here’s the fun part β€” summarizing key log files for:

  • syslog (general issues)
  • auth.log (SSH logins/failures)
  • Apache error logs
  • WordPress debug logs
bashCopyEditecho ""
echo "πŸ“œ Log Summary (last 10 relevant entries):"

echo "β€’ Syslog:"
grep -iE "error|fail|warn" /var/log/syslog | tail -n 10 2>/dev/null

echo "β€’ SSH Logs:"
grep -iE "Accepted|Failed|authentication failure" /var/log/auth.log | tail -n 10 2>/dev/null

echo "β€’ Apache Errors:"
tail -n 10 /var/log/apache2/error.log | grep -iE "error|warn|fail" 2>/dev/null

wp_log="/var/www/html/wp-content/debug.log"
if [ -f "$wp_log" ]; then
    echo "β€’ WordPress Errors:"
    tail -n 10 "$wp_log" | grep -iE "error|warn|notice"
fi

This gives me daily visibility of real issues β€” without digging through log files manually.


πŸͺœ Step 8: Add ⏰ Time-Based Greetings

hour=$(date +"%H")
if [ "$hour" -lt 12 ]; then
greeting="πŸŒ… Good morning"
elif [ "$hour" -lt 18 ]; then
greeting="β˜€οΈ Good afternoon"
else
greeting="πŸŒ™ Good evening"
fi

echo "β•‘ $greeting! β•‘"

A simple touch that adds personality to the login experience.


βœ… Final Result: Beautiful, Intelligent MOTD

Edit╔══════════════════════════════════════╗
β•‘ πŸš€ Welcome to MKCloudAI Server β•‘
╠══════════════════════════════════════╣
β•‘ β˜€οΈ Good afternoon! β•‘
β•‘ πŸ”’ Secured Ubuntu Server - DevOps β•‘
β•‘ πŸ•’ Uptime: up 7 days, 3 hours β•‘
β•‘ πŸ’‘ Tip: Keep your system updated! β•‘
β•šβ•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•

🌐 Hostname: ip-172-26-8-36
πŸ•’ Uptime: up 7 days, 3 hours
πŸ’Ύ Disk Usage: 83% used
🧠 Memory Usage: 55.4% used
🚨 ALERT: Root disk usage is above 80% (83%)
☁️ AWS Instance ID: i-xxxxxxxxx
☁️ AWS Type: t3.micro | Region: eu-west-2
❌ Failed Services:
β†’ apache2.service (failed)
πŸ“… Upcoming Cron Jobs:
β†’ 0 4 * * * /usr/bin/apt upgrade
πŸ“œ Log Summary:
β€’ SSH Logs:
Failed password for root from 192.168.1.10
Accepted publickey for ubuntu from 172.20.1.5
...

πŸ›‘οΈ Final Tips

  • Make sure your script is executable:
    chmod +x /etc/update-motd.d/99-custom
  • Test it with:
    run-parts /etc/update-motd.d/
  • For persistent MOTD updates, avoid static /etc/motd.

πŸ“Œ Summary

With just one script, I turned a boring login into a DevOps dashboard that:

  • Shows alerts
  • Tracks logs
  • Surfaces metadata
  • Adds personality

If you’re managing AWS servers or want a smart CLI dashboard β€” try this out and customize it for your own workflows.


πŸ™‹ Want the Full Script?

πŸ‘‰ Download it from GitHub Gist (link your repo)
πŸ‘‰ Or contact me via mkcloudai.com

Scroll to Top