Spice up your Message of the Day ( motd )

dos2unix

Well-Known Member
Joined
May 3, 2019
Messages
3,525
Reaction score
3,290
Credits
31,524
Most Linux systems have a "message of the day" file. This is almost always located at /etc/motd

This is just a text file, you can put any text you want in this file. It doesn't affect anything except the message you see
when you first login the command line. If you have a server with no GUI, this is what you will see at the login prompt.
If you use ssh or or login thru the serial port, this message will be first thing you will see once you login.

A few examples of what you might want to put here.

Code:
Welcome to [Your System Name]!

Have a great day!

Code:
Welcome to [Your System Name]!Server IP: [Your Server IP]Uptime: $(uptime -p)Users: $(who | wc -l)

Code:
"The only way to do great work is to love what you do." - Steve Jobs

Did you know? Honey never spoils. Archaeologists have found pots of honey in ancient Egyptian tombs that are over 3000 years old and still perfectly edible.

Code:
IMPORTANT: Scheduled Maintenance

Date: [Maintenance Date]
Time: [Maintenance Time]
Duration: [Expected Duration]

Please save your work and log out before the maintenance begins. Thank you!

Code:
Welcome to [Your System Name]!

<pre>
  _     _                    ___              ____            _        _
 | |   (_)_ __  _   ___  __ / _ \ _ __ __ _  |  _ \ ___   ___| | _____| |
 | |   | | '_ \| | | \ \/ /| | | | '__/ _` | | |_) / _ \ / __| |/ / __| |
 | |___| | | | | |_| |>  < | |_| | | | (_| | |  _ < (_) | (__|   <\__ \_|
 |_____|_|_| |_|\__,_/_/\_(_)___/|_|  \__, | |_| \_\___/ \___|_|\_\___(_)
                                      |___/                             
</pre>

Note: you don't need the "<pre>" tags, I just had to use them here, so the text would display correctly.
 
Last edited:


Well, I suppose all of that is cool, but we can do better. What if I want to colorize my text output?

I can do something like this.
Code:
<pre>
#!/bin/bash
echo -e "\033[34m  _     _                    ___              ____            _        _ \033[0m"
echo -e "\033[34m | |   (_)_ __  _   ___  __ / _ \ _ __ __ _  |  _ \ ___   ___| | _____| |\033[0m"
echo -e "\033[34m | |   | | |_ \| | | \ \/ /| | | | |__/ _  | | |_) / _ \ / __| |/ / __| |\033[0m"
echo -e "\033[34m | |___| | | | | |_| |>  < | |_| | | | (_| | |  _ < (_) | (__|   <\__ \_|\033[0m"
echo -e "\033[34m |_____|_|_| |_|\__,_/_/\_(_)___/|_|  \__, | |_| \_\___/ \___|_|\_\___(_)\033[0m"
echo -e "\033[34m                                      |___/\033[0m"
</pre>

(again, we don't need the "<pre>" tags).

But the problem is, now it's not just text anymore, it's bash shell script.
So instead of putting this file at /etc/motd
We name it motd.sh and put it at /etc/profile.d/motd.sh

There are other colors and other unicode characters you can use, this is just a start.

You can also have both a /etc/profile.d/motd.sh bash script and a /etc/motd text file.
Your login will display both. Have fun trying new ideas. Feel free to post any cool ideas you have about this.
 
Last edited:
Here is a quick script I made a while back to display the unicode charcters.

Code:
#!/bin/bash

# Array of unique Unicode box-drawing characters
box_drawing_chars=(
    "\u2500" "\u2501" "\u2502" "\u2503" "\u2504" "\u2505" "\u2506" "\u2507"
    "\u2508" "\u2509" "\u250A" "\u250B" "\u250C" "\u250D" "\u250E" "\u250F"
    "\u2510" "\u2511" "\u2512" "\u2513" "\u2514" "\u2515" "\u2516" "\u2517"
    "\u2518" "\u2519" "\u251A" "\u251B" "\u251C" "\u251D" "\u251E" "\u251F"
    "\u2520" "\u2521" "\u2522" "\u2523" "\u2524" "\u2525" "\u2526" "\u2527"
    "\u2528" "\u2529" "\u252A" "\u252B" "\u252C" "\u252D" "\u252E" "\u252F"
    "\u2530" "\u2531" "\u2532" "\u2533" "\u2534" "\u2535" "\u2536" "\u2537"
    "\u2538" "\u2539" "\u253A" "\u253B" "\u253C" "\u253D" "\u253E" "\u253F"
    "\u2540" "\u2541" "\u2542" "\u2543" "\u2544" "\u2545" "\u2546" "\u2547"
    "\u2548" "\u2549" "\u254A" "\u254B" "\u254C" "\u254D" "\u254E" "\u254F"
    "\u2550" "\u2551" "\u2552" "\u2553" "\u2554" "\u2555" "\u2556" "\u2557"
    "\u2558" "\u2559" "\u255A" "\u255B" "\u255C" "\u255D" "\u255E" "\u255F"
    "\u2560" "\u2561" "\u2562" "\u2563" "\u2564" "\u2565" "\u2566" "\u2567"
    "\u2568" "\u2569" "\u256A" "\u256B" "\u256C" "\u256D" "\u256E" "\u256F"
    "\u2570" "\u2571" "\u2572" "\u2573" "\u2574" "\u2575" "\u2576" "\u2577"
    "\u2578" "\u2579" "\u257A" "\u257B" "\u257C" "\u257D" "\u257E" "\u257F"
)

# Print each character
for char in "${box_drawing_chars[@]}"; do
    printf "$char "
done

# Print a newline at the end
echo

Here is a colorization script.

Code:
#!/bin/bash

# Define ANSI color codes
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[0;33m'
BLUE='\033[0;34m'
MAGENTA='\033[0;35m'
CYAN='\033[0;36m'
RESET='\033[0m'

# Print colorized box-drawing characters
printf "${RED}\u2554\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2557${RESET}\n"
printf "${GREEN}\u2551${YELLOW} LINUX/ ${GREEN}\u2551${RESET}\n"
printf "${GREEN}\u2551${CYAN}  ORG  ${GREEN}\u2551${RESET}\n"
printf "${RED}\u255A\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u255D${RESET}\n"
 
Last edited:
I use a script that runs at system startup to "fix" motd with the distro's logo, version and architecture and the hostname. No colors nor anything fancy except the little penguin's eye is a non-ascii character (the "degree" symbol) so it sometimes renders as the console equivalent of a "tofu".

Code:
(°-   
//\    Core Linux mb 15.0 x86_64
v_/_       dolly

The "mb" indicates that I was playing around with learning how to remaster the initrd, though, TBH, adding the "mb" in /etc/issue was the -only- change in this "remaster" - just a proof of concept exercise.

The script, updated today, looks like this:
Code:
#!/bin/sh
# fix_motd - fix /etc/motd w/core logo, version and    lem 2024-12-24 21:49
#            arch and hostname

LOGO="/opt/motd_logo"
ARCH="`uname -m`"
VER="`cat /etc/os-release |grep -E "^VERSION=" |cut -d= -f2 |tr -d '\"'`"
KRNL="`uname -r`"
HOST="`uname -n`"
OS="`cat /etc/issue`"

RECNO=0
cat "${LOGO}" |while read REC ; do
  RECNO="`expr ${RECNO} + 1`"
  REC="`echo "${REC}" |tr "." " "`"
  [ "${RECNO}" = 2 ] && echo "${REC} ${OS} ${VER} ${ARCH}" && continue
  [ "${RECNO}" = 3 ] && echo "${REC}     ${HOST}"          && continue
  echo "${REC}"
done
 


Members online


Top