Skip to content

Instantly share code, notes, and snippets.

@bearlike
Last active June 9, 2022 00:51
Show Gist options
  • Save bearlike/d5c90dd24e43e0c5cf89342ac4331358 to your computer and use it in GitHub Desktop.
Save bearlike/d5c90dd24e43e0c5cf89342ac4331358 to your computer and use it in GitHub Desktop.
Dynamic banner for each time that you login through SSH.

Raspberry Pi – Awesome custom MOTD

Introduction

Even though the Raspberry Pi comes with an HDMI port, most projects are headless (runs without a display), which suggests you're mostly using SSH to access the system. I'm bored of seeing the most basic login banner, so I've played around a little bit and added something a little more useful. This login banner is your MOTD (Message of the day, Linux term).

How to do it?

Open /home/<user>/.bash_profile if you're using Raspberry Pi OS (aka. Raspbian). First you need to edit your profile:

sudo nano /home/pi/.bash_profile # mostly, the user is "Pi"

Then just past in the code below, anywhere within that file:

clear 
echo "$(tput bold)$(tput setaf 2)"
echo "    .~~.   .~~.  "
echo "   '. \ ' ' / .' "
echo "$(tput setaf 1)"
echo "    .~ .~~~..~.   "
echo "   : .~.'~'.~. :  "  
echo "  ~ (   ) (   ) ~ "  
echo " ( : '~'.~.'~' : )"    
echo "  ~ .~ (   ) ~. ~ "  
echo "   (  : '~' :  )  "  
echo "    '~ .~~~. ~'   "
echo "        '~'      "
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"`
`uname -srmo`

$(tput sgr0)- Uptime.............: ${UPTIME}
$(tput sgr0)- Memory.............: `free | grep Mem | awk '{print $3/1024}'` MB (Used) / `cat /proc/meminfo | grep MemTotal | awk {'print $2/1024'}` MB (Total)
$(tput sgr0)- Load Averages......: ${one}, ${five}, ${fifteen} (1, 5, 15 min)
$(tput sgr0)- Running Processes..: `ps ax | wc -l | tr -d " "`
$(tput sgr0)- IP Addresses.......: `hostname -I | /usr/bin/cut -d " " -f 1` and `wget -q -O - http://icanhazip.com/ | tail`

$(tput sgr0)"

Output

    .~~.   .~~.  
   '. \ ' ' / .' 
    .~ .~~~..~.   
   : .~.'~'.~. :  
  ~ (   ) (   ) ~ 
 ( : '~'.~.'~' : )
  ~ .~ (   ) ~. ~ 
   (  : '~' :  )  
    '~ .~~~. ~'   
        '~'      

Sunday,  7 June 2020, 05:45:44 PM
Linux 4.19.118-v7l+ armv7l GNU/Linux

- Uptime.............: 0 days, 01h30m26s
- Memory.............: 167.457 MB (Used) / 3906 MB (Total)
- Load Averages......: 0.13, 0.06, 0.02 (1, 5, 15 min)
- Running Processes..: 125
- IP Addresses.......: 192.168.1.29 and 171.60.203.91

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment