MOTD Greeting for Linux with System Information

Martin Döring, 8th of September 2021

When you log on to Linux, you are usually greeted with some information called the message of today (MOTD). On Ubuntu or Arch this is located in the directory /etc/update-motd.d/ in the form of individual executable files that deliver certain information. The files are executed or displayed in the order of their numbering.

To get more concise and meaningful information for my system after login, I built the following file 00-system-info, which shows me some data about my computer like this, here an example:

The script:

#!/bin/bash
#
# File: 00-system-info - create the MOTD
# Copyright: (C) Martin Doering <martin@datapulp.de>
# License: Public Domain (do what you want with it)
#

diskusage=$(df -H -x squashfs -x tmpfs -x devtmpfs --total|grep total)

printf "%`tput cols`s"|tr ' ' '#'
echo " Hostname: $(hostname)"
echo " Distro: $(lsb_release -s -d)"
echo
echo " CPU: $(cat /proc/cpuinfo | grep 'model name' | head -1 | cut -d':' -f2)"
echo " Disk: $(echo $diskusage | awk '{ a = $2 } END { print a }'|sed 's/G/ G/'|sed 's/T/ T/')"
echo " Memory: $(free -m | head -n 2 | tail -n 1 | awk {'print $2'}) M"
echo " Swap: $(free -m | tail -n 1 | awk {'print $2'}) M"
echo

if which ip >/dev/null
then
echo " IP V4 Networks"
ip -o -4 -br a|grep -v '^lo'|sed 's/^/ /'|sed 's/\/..//'
echo
echo " IP V6 Networks"
ip -o -6 -br a|grep -v '^lo'|sed 's/^/ /'|sed 's/\/..//'
fi
printf "%`tput cols`s"|tr ' ' '#'

The script has been tested on Ubuntu and Raspian. On systems that do not have the ip command, the lower network part must be adjusted, otherwise nothing will be displayed.

——

back