Posted by: Josh Moles | January 21, 2009

Supercharge the Ubuntu MOTD

The Message of the Day (MOTD) is the first thing you see when you log in to a Linux machine on the command prompt. If you see it every time you log in, why not make some changes to actually make it useful? I find it useful to have my MOTD display some system information (like uptime, disk usage, etc.) when I first log-in to my server. Here is some info about the MOTD and how to make it a little more dynamic.

/etc/motd and /etc/motd.tail

These two files are the basic part of the MOTD. On every boot up, the /etc/motd file is erased and regenerated from the contents of /etc/motd.tail. If you want to display a message that is only seen until the next time your system restarts, then put it in /etc/motd. Unless you have multiple users logging into your server and want to give them a message on the prompt, you generally will not need to edit /etc/motd. I have an ASCII art of the server’s name ASCII Generator in /etc/motd.tail and generally don’t modify /etc/motd.

System Information with landscape-sysinfo

I won’t go into detail about what Canoncial’s Landscape is besides the fact there is a tool  have a tool that can generate a nice MOTD with system information like the one here:

System load:    0.01                  Swap usage:  0%           Users logged in: 1
Usage of /home: 15.5% of 4.62GB    Temperature: 40 C
Memory usage:   41%                  Processes:   149

This addition to the MOTD is easy to add and only requires the installation of the landscape-common package. This can be done by running:

sudo apt-get install landscape-common

Now, log out, log in again, and then you should now see the same information above on your MOTD.

Custom Scripts with update-motd

If you installed landscape-common on the previous step, update-motd was also installed on your system. This package allows you to make your own scripts to display information on the MOTD.

First, you must install update-motd by running (note, if you installed landscape-common, it is already installed):

sudo apt-get install update-motd

After the install finishes, go to the directory /etc/update-motd.d/. This directory contains the scripts that are ran when the MOTD is generated. They are ran and displayed in the MOTD in lexical sort order. The safest way to control the order they appear is to prefix the files with numbers. As an example, I made a file called 10-server-info and put the following in it:

#!/bin/sh
echo "Disk Usage:"
df -h
echo "System Uptime:"
uptime

This script will add the hard drive usage and the system uptime to my MOTD and it will run and display in the MOTD. Don’t forget to make it executeable before continuing:

sudo chmod +x 10-server-info

So let’s say I wanted to also display the time before the disk usage and uptime. I could do this by making a file called 09-time and put the following in it:

#!/bin/sh
echo "Current Time:"
date

To have it display the time after the first script (10-server-info), I could just name it something with a number greater than 10, like 11-time.
After you are happy with all of the scripts, finally run the following to turn on update-motd and have it start generating updated MOTD:

sudo update-motd --enable

Log out, log back in, and you should see the updated MOTD. In the future, if you add or remove scripts, you can have the MOTD updated by running:

sudo update-motd

update-motd is powerful because you can run pretty much any shell script you can come up with and display the results on the MOTD. If you aren’t too familiar with shell scripts, check out the Advanced Bash-Scripting Guide.


Responses

  1. thanks for these very useful tips.

    it seems that documentation on landscape-sysinfo does not exist.
    anywhere.
    no man page is installed and nothing is available on the canonical site that documents this.
    [it's rather obnoxious to NOT have a man page for something installed by default]

    i am trying to make it display the cpu temp in fahrenheit rather than celsius.
    it appears to be impossible.

    any idea how to force this to fahrenheit?

  2. I know if you use Ubuntu or Noobuntu (as I like to call it) then you aren’t the Josh I know.

  3. Jeff: Not quite sure on the Fahrenheit. I will keep checking around and try to find out. I am sure you could maybe do some sed/awk stuff if all comes to worse to get it working.


Leave a response

Your response:

Categories