HOWTO: Dynamic MOTD for Debian Bullseye GNU/Linux

Questions and discussion about web design, search engine optimisation and hosting
Santeri
Posts: 287
Joined: 2017-7-5 09:58

Unread post by Santeri » 2021-12-22 21:58

Would you like to have a dynamic message of the day (MOTD) when you log in to your Debian Bullseye?
Image Here are the steps to make that happen. First edit the current motd script:

Code: Select all

sudo nano /etc/update-motd.d/10-uname
and replace the original code with the following code:

Code: Select all

#!/bin/sh
# Replace /etc/update-motd.d/10-uname with this script to get a dynamic MOTD in Debian Bullseye
# After that delete the current motd: sudo rm /etc/motd
# Santeri Kannisto <santeri.kannisto@webseodesigners.com>
# Public domain, 2021
# Support: https://forum.webseodesigners.com/web-design-seo-and-hosting-f16/howto-dynamic-motd-for-debian-bullseye-gnu-linux-t4558.html
printf "\n%s (%s)\n" "$(lsb_release -s -d)" "$(uname -r)"
printf "System information on %s\n\n" "$(date)"
printf "System Load:\t%s\tIP Address:\t%s\n" "$(cat /proc/loadavg | awk '{print $1}')" "$(hostname -I | awk '{print $1}')"
printf "Memory Usage:\t%s\tSystem Uptime:\t%s\n" "$(free -m | awk '/Mem:/ { total=$2; used=$3 } END { printf("%3.1f%%", used/total*100)}')" "$(uptime | grep -ohe 'up .*' | sed 's/,/\ hours/g' | awk '{ printf $2" "$3 }')"
printf "Disk Usage:\t%s\tProcesses:\t%s\n" "$(df -h / | awk '/\// {print $(NF-1)}')" "$(ps aux | wc -l)"
printf "Swap Usage:\t%s\tLocal Users:\t%s\n\n" "$(free -m | awk '/Swap/ { printf("%3.1f%%", $3/$2*100) }')" "$(users | wc -w)"
Then delete the current motd:

Code: Select all

sudo rm /etc/motd
The next time your login, you will see something like this:

Debian GNU/Linux 11 (bullseye) (5.10.0-9-amd64)
System information on Wed Dec 22 23:45:16 EET 2021

System Load:    0.00    IP Address:     172.22.214.86
Memory Usage:   11.0%   System Uptime:  1:14 hours
Disk Usage:     16%     Processes:      87
Swap Usage:     0.0%    Local Users:    1

Last login: Wed Dec 22 22:56:09 2021 from 172.22.208.1

Happy hacking,

Santeri



Post Reply