How to change message of the day (MOTD) in Ubuntu server

Sponsored Link
The contents of /etc/motd are displayed by login after a successful login but just before it executes the login shell.

The abbreviation "motd" stands for "message of the day", and this file has been traditionally used for exactly that (it requires much less disk space than mail to all users).

If you want to change this message in ubuntu server follow this procedure first you need to edit /etc/motd.tail file

sudo vi /etc/motd.tail

Enter your message save and exit the file

Now you can restart your ubuntu server to check your changes are working or not

For Ubuntu Intrepid Users

There is a new package that provides this functionality with more options, called update-motd, available in Ubuntu Universe for Intrepid.

Install update-motd in Ubuntu Intrepid

sudo aptitude install update-motd

This will complete the installation

This package seeks to make the /etc/motd (Message of the Day) more dynamic and valuable, by providing a simple, clean framework for defining scripts whose output will regularly be written to /etc/motd.

The update-motd package creates a directory, /etc/update-motd.d, and installs a cronjob, /etc/cron.d/update-motd, which calls /usr/sbin/update-motd every 10 minutes (by default).

/usr/sbin/update-motd uses run-parts to execute each script in /etc/update-motd.d in lexigraphic order, concatenating the results with the message-of-the-day header, /etc/motd.tail.

In this way, users, or even other packages can drop scripts into /etc/update-motd.d to affect the MOTD.

Example

create a script, such as /etc/update-motd.d/10-stats

sudo vi /etc/update-motd.d/10-stats

add the following lines and save the file.

#!/bin/sh
echo
date
echo
who
echo

Make sure you chmod +x /etc/update-motd.d/10-stats.Then, you can either run /usr/bin/update-motd, or uptimeWait ~10 minutes and then log in.

This is very simple and great idea where you can see whatever information you want when you login in to your server.

Sponsored Link

Incoming search terms:

Related posts

9 thoughts on “How to change message of the day (MOTD) in Ubuntu server

  1. I think you will find that /etc/motd is only displayed on text-logins, not GUI ones (on what used to be init level 3, if that helps explain anything).

    So — unless I’m mistaken — the vast majority of us don’t see that text.

    [Reply]

  2. The contents of /etc/motd are displayed by login after a successful login but just before it executes the login shell.

    it depends on the telnet/ssh server. Some do, some don’t

    Not really.I have been using debian,ubuntu,redhat linux servers everytime when you login using ssh or telnet you should see similar to the following message

    Linux t61p 2.6.26-5-generic #1 SMP Fri Aug 15 13:54:22 UTC 2008 x86_64

    The programs included with the Ubuntu system are free software;
    the exact distribution terms for each program are described in the
    individual files in /usr/share/doc/*/copyright.

    Ubuntu comes with ABSOLUTELY NO WARRANTY, to the extent permitted by
    applicable law.

    To access official Ubuntu documentation, please visit:
    http://help.ubuntu.com/

    [Reply]

  3. LOL :)

    P.S. Thanks for the article! Interesting and actual as I’ve been just searching for this howto.

    [Reply]

  4. ### Posted for Posterity ###
    Ubuntu 10.04 LTS 32-Bit Server Edition
    I run a headless server as a gateway, the “Message of The Day” is an essential tool for quickly seeing what is happening on a server. The “motd” script is also linked to my aliases file so that this info can be accessed quickly.

    ### Fiction About “update-motd” ###

    The update-motd package creates a directory “/etc/update-motd.d” (TRUE)
    Installs a cronjob, “/etc/cron.d/update-motd” (NOT!!!)
    Cron calls /usr/sbin/update-motd every 10 minutes by default (NOT!!!)

    The command “/usr/sbin/update-motd” uses run-parts to execute each script in /etc/update-motd.d in lexigraphic order, concatenating the results with the message-of-the-day header “/etc/motd.tail”. (NOT!!!)

    ### The TRUTH About MOTD ###
    Follow these steps:

    1) Install the helper package for customizing motd.
    apt-get install update-motd

    2) Make ONE executable script in “/etc/update-motd.d”. Get rid of all the other scripts in /etc/update-motd.d and use ONE script “10-scriptname”, where “scriptname” is the name of your file without any file extensions. For some reason, all the other scripts you try to create will NEVER get executed.

    3) Make a symlink in “/etc/update-motd.d” to a script in a SAFE directory just to be sure that you never lose it (just in case there is a distro update and update-motd gets DEPRECATED).
    cd /etc/update-motd.d
    ln -s /path/to/your/script 10-scriptname

    4) An updated motd will be created ONLY when you login. The “/usr/sbin/update-motd” command does not exist anymore. The cron job is also now fictional/legendary.

    5) Fact: “update-motd” is already partially deprecated (see below)
    Name: update-motd
    Description: superceded by pam_motd in libpam-modules
    http://www.ubuntuupdates.org/packages/show/162501

    Here is a sample script for some very useful (not annoying) information:

    #!/bin/bash
    function mydate(){
    strDayofMonth=$(date +%d)
    intLength=${#strDayofMonth}
    intOff=$(($intLength-1))
    strDayPart=${strDayofMonth:intLength:intOff}

    case $strDayPart in

    1)
    strOrdinal=”st”
    ;;

    2)
    strOrdinal=”nd”
    ;;

    3)
    strOrdinal=”rd”
    ;;

    *)
    strOrdinal=”th”
    ;;

    esac
    day=$(date +%d | sed ‘s/^0//’)
    myDate=$(date +%A” “%B” $day$strOrdinal, “%Y” at “%l”:”%M%P” “%Z)
    }

    echo

    ### START MESSAGE OF THE DAY ###
    cal
    echo -n “\”$(hostname)\” $(cat /etc/issue)-$(uname -r)”;echo
    mydate
    echo $myDate
    echo

    ### PHYSICAL DRIVE USAGE ###
    drives=$(df | grep “/dev/sd” | awk ‘{print $1}’)
    echo “Disk Usage”
    echo “———-”
    echo “$(df -h –total $drives)”
    echo

    ### IPV4 INTERFACE INFORMATION ###
    echo “Interfaces”
    echo “———-”
    list=$(ifconfig | grep “eth” | awk ‘{print $1}’)
    for item in $list; do
    address=$(ifconfig $item | grep “inet addr” | awk ‘{print $2}’ | cut -d “:” -f2)
    echo “IPV4 Address of $item is $address”
    done
    echo

    ### SYSTEM INFORMATION ###
    echo “System Info”
    echo “———–”
    pcount=$(ps aux | wc -l)
    phymem=$(free -m | grep “Mem:” | awk ‘{printf “%d%%\n”, $3*100/$2}’)
    swapmem=$(free -m | grep “Swap:” | awk ‘{printf “%d%%\n”, $3*100/$2}’)
    echo “Total Processes: $pcount”
    echo “Physical memory usage: $phymem”
    echo “Swap memory usage: $swapmem”
    echo

    ### USER LOGIN INFORMATION ###
    echo “Login Info”
    echo “———-”
    logins=$(who | wc -l)
    echo “Number of users logged in: $logins”
    who
    echo

    exit 0

    [Reply]

Leave a comment

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