<img height="1" width="1" src="https://www.facebook.com/tr?id=1076094119157733&amp;ev=PageView &amp;noscript=1">

I'll call him Moose

Posted by alex lashford on Mon, Jul 10, 2017

We embrace modern DevOps practices at Cake, so we are very much of the opinion that making all servers “cattle” not “pets” is the only way to provision. However, occasionally we do need a pet, we will call him “Moose”.

I’ll call him “Moose”

Now, when logging onto Moose via ssh, do you get that boring message from your defacto linux distro. Well lets look at how we can customise that, there are probably some useful reasons to do this, but I’m doing it, because well its fun …

MOTD

All you English football fans may be confused to hear, this does not stand for Match Of The Day. But for Message Of The Day. This is a standard application built into many linux distributions. On Debian based releases you can find the files in this directory.

/etc/update-motd.d/

Under this directory you will most likely find a several numbered files.

root@ubuntu:/etc/update-motd.d/# ls
0-header 01-sysinfo 10-help 90-updates-available 
91-release-upgrade 

These files are executed in file name order, hence the number prefix. When a user logs into the OS the scripts are executed. These are just 'bash' files and can be executed manualy to see the output.

sh /etc/update-motd.d/00-header

Custom Header

So lets create a custom message with some ascii art and system info. Editing the first file executed, (often 00-header) we can add some content, you should pay special attention to the echo command for the ascii art, as this allows us print some special chars.


Edit the header file vi /etc/update-motd.d/00-header

echo
cat << "EOF"
.--,    .--,    _____
(( \.---./ ))   /   \ ____ ____ ______ ____
'.__/o o\__.'  / \ / \ / _ \ / _ \/ ___// __ \
   {= ^ =}    /   Y   ( <_> | <_> )___ \\ ___/
    > - <    \____|__ /\____/\____/____ >\___ >
      ^         
EOF
echo
printf " Welcome to the jungle - %s (%s)
" "$(lsb_release -s -d)" "$(lsb_release -c -s)"

Lets test the script

./etc/update-motd.d/00-header

System info

Its useful to see the load of the machine when you login, so lets create a nice overview. As with most things in the linux world something for this already exists. Hurahhh. landscape-sysinfo is a package that well you guessed it prints a system status.

Lets create another file and the following content. vi /etc/update-motd.d/01-sysinfo

#!/bin/sh
echo
echo 'System Information:'
echo
landscape-sysinfo --exclude-sysinfo-plugins=LandscapeLink
echo

before the new script will run you need to make it executable.
chmod +x /etc/update-motd.d/01-sysinfo
Lets take a look at all this together, logout of the machine and log back in. Hopefully it looks like this …

.--,    .--,    _____
(( \.---./ ))   /   \ ____ ____ ______ ____
'.__/o o\__.'  / \ / \ / _ \ / _ \/ ___// __ \
   {= ^ =}    /   Y   ( <_> | <_> )___ \\ ___/
    > - <    \____|__ /\____/\____/____ >\___ >
      ^         
Welcome to the jungle - Ubuntu 17.04 (zesty)
System Information:
System load: 0.0 Processes: 124
Usage of /: 3.8% of 109.53GB Users logged in: 1
Memory usage: 10% IP address for ens2: 192.168.88.99
Swap usage: 0% IP address for docker0: 172.17.0.1

Don’t be a Square

If you want to have something funky like moose the mouse holding up a sign with a custom message, try this…

Install the boxes package

apt-get install boxes

Create a file called 05-mouse-info

vi 05-mouse-info

With contents ...

#!/bin/bash
boxes -a c -d mouse <<< "$(lsb_release -s -d) ($(lsb_release -c -s))"
echo

Make the file executable and then test it out.

chmod +x 05-mouse-info
./05-mouse-info

Resulting in ...

        .--, .--,
     ( ( \.---./ ) )
      '.__/o o\__.'
         {= ^ =}
          > - <
 ____.""`-------`"".___
/                       \
\ Ubuntu 17.04 (zesty)  /
/                       \
\______________________ /
       ___)( )(___
      (((__) (__)))

Boxes has a ton of cool ascii art check them out boxes -l


So why not create a move welcoming message for your favourite pet. #hellomoose

Other Distributions

Remember the above code is just a bash script at the end of the day. So if your OS does not have MOTD built in, you could simply add the above to a bash script and run it from ~/.bash_profile , similar scripts are executed for all shells be that ZSH, tcsh or sh.

Speak soon.

Links:
Generate ascii words -> http://patorjk.com/software/taag/
Find some cool ascii images -> http://www.asciiworld.com

Topics: DevOps, MOTD, Bash, AsciArt

Recent Posts

Posts by Topic

see all

Subscribe to Email Updates