How to Create a Custom Linux MOTD Screen

Creating a custom Message of the Day (Linux MOTD) screen on Linux involves modifying certain files and configurations. We’ll use the /etc/update-motd.d/ directory to add scripts that fetch and display relevant information.

Source: Unix.StackExchange.com

Creating a Custom Linux MOTD: Enhanced Guide

Understanding MOTD:

The Message of the Day (MOTD) is a brief message displayed to users when they log into a Linux system. It can contain welcome messages, system information, announcements, or even artistic ASCII banners.

Prerequisites:

  • Terminal Access: You’ll need access to a terminal on your Linux system.
  • Basic Text Editor Knowledge: You’ll use a text editor like nano to create and modify files.

Step 1: Access the Terminal and Check MOTD is installed

Open a terminal on your Linux system.

Bash
sudo apt-get install --reinstall update-motd

While most Linux systems have MOTD enabled by default, this command ensures it’s installed and up-to-date. The update-motd package is crucial for generating dynamic MOTDs.


Step 2: Backup Existing Linux MOTD and Update Scripts (Optional)

Backup the existing MOTD file and update scripts:


The Message of the Day (MOTD) in Linux is typically stored in the “/etc/motd” file. In some versions of Ubuntu and Debian, it’s located in “/etc/update-motd.d”.

Bash
sudo cp /etc/motd /etc/motd_backup 
sudo cp -r /etc/update-motd.d/ /etc/update-motd.d_backup


Step 3: Create Custom Linux MOTD Scripts

Create custom scripts in the /etc/update-motd.d/ directory to fetch and display dynamic information. For example, create a script named 10-custom-info:

Bash
sudo nano /etc/update-motd.d/10-custom-info

Add the following content to the script:

Bash
#!/bin/bash

# Gather System Information
WHO=$(who | awk '{print $1}' | sort | uniq)  
CPU=$(top -bn1 | grep "Cpu(s)" | sed "s/.*, *\([0-9.]*\)%* id.*/\1/" | awk '{print 100 - $1}')
DISK=$(df -h / | awk 'NR==2 {print $5}')
RAM=$(free -m | awk 'NR==2 {printf "%.1f%%", $3/$2*100}')

# Display Welcome Message
echo "Welcome to [Your System Name]!"
echo "============================="

# Display Dynamic Information (Customizable)
echo "Logged in users: $WHO"
echo "CPU Usage: $CPU%"
echo "Disk Usage (/): $DISK"
echo "RAM Usage: $RAM"

This script:

  • Gathers user logins (who), CPU usage (top), disk usage (df), and RAM usage (free).
  • Displays a welcome message.
  • Presents the gathered information in a readable format.
  • Customize: Feel free to modify the welcome message, add more system details (e.g., uptime, IP address), or incorporate ASCII art.

Save the script and make it executable:

Bash
sudo chmod +x /etc/update-motd.d/10-custom-info

Need inspiration? Check out this MOTD Creator.


Step 4: Edit the MOTD File

Edit the main MOTD file to include a reference to the custom scripts:

Bash
sudo nano /etc/motd

Add the following line at the end of the file:

Bash
cat /etc/update-motd.d/10-custom-info


Step 5: Save and Exit

Save the MOTD file and exit the text editor.


Step 6: Test the MOTD

Log out and log back in, or open a new terminal window. Your custom MOTD with dynamic system information should now be displayed.


Step 7: Optional – Update MOTD

Some systems may require you to update the MOTD manually:

Bash
sudo update-motd

Now, each time a user logs in, they’ll see dynamic system information in the MOTD, including who is logged on, CPU usage, disk usage, and RAM usage. Feel free to customize the script further to include additional information if needed.


Advanced Tips:

  • Colorize Your MOTD: Use ANSI escape codes to add color to your output.
  • External Tools: Consider using tools like figlet (for ASCII art) or boxes (for decorative boxes).
  • Security: Avoid displaying sensitive information in your MOTD.
  • Performance: Be mindful of resource-intensive commands in your scripts, especially if your system has limited resources.

Try this Killer MOTD screen

#!/bin/bash

# ==========================================
# Stunning MOTD with Advanced Information
# ==========================================

# User Information
USER=$(whoami)
FULLNAME=$(getent passwd "$USER" | cut -d: -f5 | cut -d, -f1)
LAST_LOGIN=$(last -n 1 $USER | head -n 1 | awk '{ print $5, $6, $7 }')
SHELL=$(getent passwd "$USER" | cut -d: -f7)

# System Information
HOSTNAME=$(hostname)
UPTIME=$(uptime -p)
LOAD=$(uptime | awk '{print $8,$9,$10}' | sed 's/,//g')
IP_ADDRESS=$(ip addr show | grep -oP 'inet \K[\d.]+' | head -n 1)

# Disk Usage
DISK_ROOT=$(df -h / | tail -1 | awk '{print $5}')
DISK_OVERVIEW=$(df -h | awk '{print $1, $5}' | tail -n +2)

# Recent Logins
RECENT_LOGINS=$(last -n 5 | awk '{print $1, $3, $5, $6, $7}')

# Recent Commands
LAST_COMMANDS=$(history | tail -n 5 | awk '{print $2, $3, $4, $5, $6, $7}')

# Last Shutdown/Reboot
LAST_SHUTDOWN=$(last -x shutdown | head -n 1 | awk '{ print $5, $6, $7, $8 }')

# ==========================================
# MOTD Display (with Formatting)
# ==========================================

echo "  _   _      _ _        __        __         _     "
echo " | | | | ___| | | ___   \ \      / /__  _ __| | __ "
echo " | |_| |/ _ \ | |/ _ \   \ \ /\ / / _ \| '__| |/ / "
echo " |  _  |  __/ | | (_) |   \ V  V / (_) | |  |   <  "
echo " |_| |_|\___|_|_|\___/     \_/\_/ \___/|_|  |_|\_\ "
echo ""

echo -e "\e[1;34mWelcome back, $FULLNAME!\e[0m"
echo -e "\e[1;34mYou last logged in on $LAST_LOGIN from $IP_ADDRESS.\e[0m"
echo ""

echo -e "\e[1;32mSystem Information:\e[0m"
echo "   Hostname: $HOSTNAME"
echo "   Uptime: $UPTIME"
echo "   Load Average: $LOAD"
echo ""

echo -e "\e[1;33mDisk Usage:\e[0m"
echo "   Root (/): $DISK_ROOT"
for line in $DISK_OVERVIEW; do echo "   $line"; done
echo ""

echo -e "\e[1;35mRecent Logins:\e[0m"
for line in $RECENT_LOGINS; do echo "   $line"; done
echo ""

echo -e "\e[1;36mYour Recent Commands:\e[0m"
for line in $LAST_COMMANDS; do echo "   $line"; done
echo ""

if [ ! -z "$LAST_SHUTDOWN" ]; then
    echo -e "\e[1;31mLast Shutdown:\e[0m $LAST_SHUTDOWN"
    echo ""
fi

Alternatives to MOTD

One of my favorite alternatives to MOTD is a cool tool called neofetch

Elsewhere On TurboGeek:  How to Migrate Red Hat 5 to RHEL 6/7/8/9

Installation:

Neofetch is usually available in most package managers:

  • Debian/Ubuntu/Mint: sudo apt install neofetch
  • Fedora/CentOS/RHEL: sudo dnf install neofetch
  • Arch Linux/Manjaro: sudo pacman -S neofetch
  • macOS (Homebrew): brew install neofetch

Usage:

  • Basic: Just type neofetch in your terminal, and it will display the default information.
  • Customization: Neofetch is highly customizable:
    • Configuration File: Create a ~/.config/neofetch/config.conf file to change settings like logo, colors, info displayed, etc.
    • Command-Line Options: Use flags like --ascii_distro to change the ASCII logo or --source image to use a custom image.

Example Configuration (in config.conf)

# Use image instead of ASCII logo
image_source="wall" # Use your wallpaper
# image_source="ascii" # Use custom ASCII art
# image_source="'/path/to/your/image.png'"

# Information to display
print_info="distro title kernel uptime packages shell resolution de wm theme icons terminal cpu gpu memory"

Q&A

Q1: What is Linux MOTD and why is it important?

A1: The Linux MOTD, or Message of the Day, is a customizable screen that users see when they log into a Linux system. It serves as a welcoming message and can convey important information, updates, or announcements. Customizing the MOTD allows system administrators to provide users with relevant details at login.

Q2: How can I create a custom MOTD in Linux?

A2: Creating a custom MOTD involves editing the MOTD file or using scripts in the /etc/update-motd.d/ directory. To make the login experience unique, you can add personalized messages, ASCII art, and even dynamic system information. Check out our detailed guide for step-by-step instructions.

Q3: Can I include dynamic system information in my Linux MOTD?

A3: Absolutely! You can enhance your MOTD by adding dynamic details like who is currently logged on, CPU usage, disk space, and RAM statistics. Utilizing scripts in the /etc/update-motd.d/ directory allows you to fetch and display real-time information for users.

Q4: Why should I consider customizing the MOTD for SEO benefits?

A4: Customizing the MOTD not only enhances user experience but can also positively impact SEO. Including relevant keywords in your custom messages and regularly updating the MOTD with fresh content can contribute to improved search engine visibility for your Linux-related content.

Q5: Are there any best practices for optimizing the Linux MOTD for SEO?

A5: Absolutely! To optimize your Linux MOTD for SEO, ensure that your custom messages contain keywords related to Linux, MOTD, and any specific topics you want to highlight. Regularly update the content to keep it relevant, and consider incorporating links to relevant pages or resources within your system.

Q6: Can I track the performance of my customized Linux MOTD for SEO?

A6: Yes, you can track the performance of your customized MOTD by monitoring user engagement and analyzing web traffic. Utilize analytics tools to measure the impact of your Linux MOTD on user interaction and adjust your content strategy accordingly for continuous SEO improvement.

Thats it, hope you have fun writing your own custom MOTD. Like our Linux Procedures? Check out more here.

Richard.Bailey

Richard Bailey, a seasoned tech enthusiast, combines a passion for innovation with a knack for simplifying complex concepts. With over a decade in the industry, he's pioneered transformative solutions, blending creativity with technical prowess. An avid writer, Richard's articles resonate with readers, offering insightful perspectives that bridge the gap between technology and everyday life. His commitment to excellence and tireless pursuit of knowledge continues to inspire and shape the tech landscape.

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *

Translate ยป