Dynamic MOTD on Raspberry Pi and Odroid

May 22, 2024    Blog Post

Because it’s always nice to see something different than Last login: Wed May 22 20:33:41 2024 from 10.0.0.100

When I log in to my Raspberry Pi 1B or Odroid C1+, their terminals greet me with MOTD screens (message of the day):

RPi MOTD
Rassberry Pi

Odroid MOTD
Odroid C1+

I like these MOTD messages, and if you like them too, here’s how to implement them on your Linux systems running on Raspberry Pi or Odroid boards.

The MOTD generation script for the Raspberry Pi is from the internet and I just added a few bits to it. The script for Odroid is made by me based on Raspberry Pi.

The IP Addresses field shows IP addresses, but has been removed from the screenshots. Running Processes one, of course shows the number of all running processes in Linux and not currently processes in Running state.

There are several ways to generate MOTD messages, but I choose this one which use scripts located in /etc/update-motd.d directory.

I decided to remove all already existing scripts from /etc/update-motd.d and copy only this one, naming it 00-banner, but you can do it your own way, given that the number in the script file name indicates the order in which the script will be launched.

Raspberry Pi:
#!/bin/bash

export TERM="xterm-256color"

let upSeconds="$(/usr/bin/cut -d. -f1 /proc/uptime)"
let secs=$((${upSeconds}%60))
let mins=$((${upSeconds}/60%60))
let hours=$((${upSeconds}/3600%24))
let days=$((${upSeconds}/86400))
UPTIME=`printf "%d days, %02dh%02dm%02ds" "$days" "$hours" "$mins" "$secs"`
BOARD_TYPE=`awk -F ":" '/^Model/ { print $2 }' /proc/cpuinfo`

# get the load averages
read one five fifteen rest < /proc/loadavg

echo "$(tput setaf 2)
   .~~.   .~~.    `date +"%A, %e %B %Y, %r"`
  '. \ ' ' / .'   `uname -srmo`$(tput setaf 1)
   .~ .~~~..~.    
  : .~.'~'.~. :   Uptime.............: ${UPTIME}
 ~ (   ) (   ) ~  Memory.............: `cat /proc/meminfo | grep MemFree | awk {'print $2'}`kB (Free) / `cat /proc/meminfo | grep MemTotal | awk {'print $2'}`kB (Total)
( : '~'.~.'~' : ) Load Averages......: ${one}, ${five}, ${fifteen} (1, 5, 15 min)
 ~ .~ (   ) ~. ~  Running Processes..: `ps ax | wc -l | tr -d " "`
  (  : '~' :  )   IP Addresses.......: `/sbin/ifconfig eth0| /bin/grep -w "inet"| /usr/bin/awk '{ print $2 }'` and `wget -q -O - http://icanhazip.com/ | tail`
   '~ .~~~. ~'    Temperature........: `/opt/vc/bin/vcgencmd measure_temp|/usr/bin/awk -F '=' '{ print $2 }'`
       '~'        Board type.........: ${BOARD_TYPE:1}
$(tput sgr0)"

Odroid:
#!/bin/bash

export TERM="xterm-256color"

let upSeconds="$(/usr/bin/cut -d. -f1 /proc/uptime)"
let secs=$((${upSeconds}%60))
let mins=$((${upSeconds}/60%60))
let hours=$((${upSeconds}/3600%24))
let days=$((${upSeconds}/86400))
UPTIME=`printf "%d days, %02dh%02dm%02ds" "$days" "$hours" "$mins" "$secs"`
TEMP=$(cat /sys/devices/virtual/thermal/thermal_zone0/temp)

# get the load averages
read one five fifteen rest < /proc/loadavg

echo "$(tput setaf 4)
         #%#**#*#%#             $(tput setaf 1)`date +"%A, %e %B %Y, %r"`$(tput setaf 4)     
        %*=  +*   #%            $(tput setaf 1)`uname -srmo`$(tput setaf 4)
   %%%%%%+   +*   *%#%%%%    
%%+==#%%%+   +*   *%%*   *#%    $(tput setaf 1)Uptime.............: ${UPTIME}$(tput setaf 4)
#   =#%%%+   +*   *#      #%    $(tput setaf 1)Memory.............: `cat /proc/meminfo | grep MemFree | awk {'print $2'}`kB (Free) / `cat /proc/meminfo | grep MemTotal | awk {'print $2'}`kB (Total)$(tput setaf 4)
#   =#%*=    +*         *#%     $(tput setaf 1)Load Averages......: ${one}, ${five}, ${fifteen} (1, 5, 15 min)$(tput setaf 4)
#            +*   *    *%%      $(tput setaf 1)Running Processes..: `ps ax | wc -l | tr -d " "`$(tput setaf 4)
#     =*%+   +*   *#   *%       $(tput setaf 1)IP Addresses.......: `/sbin/ifconfig eth0| /bin/grep -w "inet"| /usr/bin/awk '{ print $2 }'`$(tput setaf 4)
#   =#%%%+   +*   *%#   #%      $(tput setaf 1)Temperature........: ${TEMP::2} C $(tput setaf 4)
#   =#%%%+  +*#*  *%%*  *#%    
#   =#%%%#*-....-*#%%%   *#     $(tput setaf 1)Board type.........: `/usr/bin/awk -F ":" '/^Hardware/ { print $2 }' /proc/cpuinfo| tr -d " "`$(tput setaf 4)
#   =#%%%%*:.  .:*%%%%#   ##    $(tput setaf 1)CPU(s).............: `grep -c "^processor" /proc/cpuinfo`$(tput setaf 4)
#=+*=-+%%%%%%##%%%%%%%*+**+##
%=..   ..+%      %%*:.  ..-#%
 %#+-:-+#%         %#=-:-+#% 

$(tput sgr0)"

Since these are scripts, after copying the appropriate one to /etc/update-motd.d, we need to add execution permissions to it by running the command chmod +x /etc/update-motd.d/00-banner.

Now we can check if it’s working by manually runing script /etc/update-motd.d/00-banner.

If everything works as expected, we can log out and log in to see if the script runs and produces the expected result.