When logging into an Ubuntu server you may have noticed the informative Message Of The Day (MOTD). This information is obtained and displayed using a couple of packages:
-
landscape-common: provides the core libraries of landscape-client, which can be used to manage systems using the web based Landscape application. The package includes the /usr/bin/landscape-sysinfo utility which is used to gather the information displayed in the MOTD.
-
update-motd: is used to automatically update the MOTD via cron.
The update-motd utility has several options to further customize the MOTD:
-
--disable: prevents automatic updates of the MOTD. Using this option creates the
/var/lib/update-motd/disabled
file, which if present stops update-motd from modifying/etc/motd
. -
--enable: enables the automatic MOTD updates. If
/var/lib/update-motd
is present it will be removed. -
--force: does a one time update of
/etc/motd
, overriding update-motd if it has been disabled. -
d, hourly, weekly, monthly: option will run the scripts in
/etc/update-motd.d/
(default),/etc/update-motd.d/hourly
,/etc/update-motd.d/weekly
, or/etc/update-motd.d/monthly
respectively.
update-motd executes the scripts in /etc/update-motd.d
in order based on the number
prepended to the script. Separate cron scripts execute every ten minutes, hourly, weekly, and monthly
running the corresponding scripts in /etc/update-motd.d
. The output of the scripts is written to
/var/run/update-motd/
, keeping the numerical order, then concatenated with
/etc/motd.tail
and written to /etc/motd
.
You can add your own dynamic information to the MOTD. For example, to add local weather information:
-
First, install the weather-util package:
sudo apt-get install weather-util
-
The weather utility uses METAR data from the National Oceanic and Atmospheric Administration and forecasts from the National Weather Service. In order to find local information you will need the 4-character ICAO location indicator. This can be determined by browsing to the National Weather Service site.
Although the National Weather Service is a United States government agency there are weather stations available world wide. However, local weather information for all locations outside the U.S. may not be available.
-
Create
/usr/local/bin/local-weather
, a simple shell script to use weather with your local ICAO indicator:#!/bin/sh ########################################################################## # # Prints the local weather to /var/run/update-motd/60-local-weather # for update-motd. # ########################################################################## # Replace KINT with your local weather station. # Local stations can be found here: http://www.weather.gov/tg/siteloc.shtml echo "" > /var/run/update-motd/60-local-weather weather -i KINT >> /var/run/update-motd/60-local-weather
-
Make the script executable:
sudo chmod 755 /usr/local/bin/local-weather
-
Next, create a symlink to
/etc/update-motd.d/60-local-weather
:sudo ln -s /usr/local/bin/local-weather /etc/update-motd.d/60-local-weather
-
Finally, update the MOTD:
sudo update-motd
You should now be greeted with some useful information, and some information about the local weather that may not be quite so useful. Hopefully the local-weather example demonstrates the flexibility of update-motd.