π§ 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 withchmod +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