Last Updated on Sep 2, 2020

Check out my custom MOTD on my Raspberry Pi, it’s showing useful data about the system right after I log in.

I used this tutorial as the basis for it.

You could add the MOTD script to the end of ~/.bashrc, but I prefer adding it to /etc/profile.d/motd.sh with 755 permissions, scripts in /etc/profile get executed after login on Raspbian.

sudo nano /etc/profile.d/motd.sh

Raspbian Stretch Lite uses systemd, so to show the status of the processes, we need to use the “grep” function of awk, and print the second and third column of the output:

# MOTD
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"`

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

echo "$(tput setaf 2)
   .~~.   .~~.    `date +"%A, %e %B %Y, %r"`
  '. \ ' ' / .'   Uptime: ${UPTIME}$(tput setaf 1)
   .~ .~~~..~.
  : .~.'~'.~. :   CPU Temperature....: `exec -- /opt/vc/bin/vcgencmd measure_temp | cut -c "6-9"`
 ~ (   ) (   ) ~  Load Averages......: ${one}, ${five}, ${fifteen}
( : '~'.~.'~' : ) Torrent Client.....: `service transmission-daemon status | awk '/Active/ {print $2 $3}'`
 ~ .~ (   ) ~. ~  NFS Server.........: `service nfs-kernel-server status | awk '/Active/ {print $2 $3}'`
  (  : '~' :  )   Connections........: Established: `sudo netstat -anp | grep -w 42423 | grep ESTABLISHED | wc -l` | All: `sudo netstat -anp | grep -w 42423 | wc -l`
   '~ .~~~. ~'    Disk Space.........: Free: `df -Ph | grep -E '^/dev/sda5' | awk '{ print $4 }'` | Used: `df -Ph | grep -E '^/dev/sda5' | awk '{ print $3 }'` $(tput setaf 2)`df -Ph | grep -E '^/dev/sda5' | awk '{ print $5 }'`$(tput setaf 1)
       '~'
$(tput sgr0)"

That’s it, you have a working MOTD on Raspbian.