update-motd(5)
โจ update-motd(5) โจ
okay so this is the File Formats Manual page for update-motd, the manual name is literally update-motd(5) ๐ let's get into it bestie ๐ซถ
๐ NAME ๐
update-motd โ dynamic MOTD generation ๐ธ
๐ง SYNOPSIS ๐ง
/etc/update-motd.d/*
๐ DESCRIPTION ๐
ngl sysadmins have been doing this forever: they keep important info for console and remote users in the file /etc/motd, and it gets shown by the pam_motd(8) module whenever someone logs into an interactive shell ๐ฅ๏ธโจ
Traditionally that file is just static text. The distro installs it and it only changes on release upgrades, or the local admin overwrites it with whatever they need to say ๐ญ
Then Ubuntu came along and introduced the update-motd framework ๐ Now the motd(5) gets dynamically assembled from a bunch of scripts every time someone logs in. iconic behavior, honestly ๐ฅ
Here's the tea: executable scripts in /etc/update-motd.d/* are run by pam_motd(8) as the root user at each login, and all their output gets concatenated into /run/motd.dynamic. The run order is decided by run-parts(8) with the --lsbsysinit option. It's basically alphabetical order, with a few caveats ๐
โ ๏ธ Scripts in /etc/update-motd.d/* run as root at every login. Keep that in mind when you write one ๐
On Ubuntu systems, /etc/motd is usually a symbolic link to /run/motd.dynamic ๐ฆ
๐ BEST PRACTICES ๐
okay here are the rules for being a good MOTD fragment ๐ซถ
- MOTD fragments have to be scripts living in
/etc/update-motd.d - They have to be executable
- They have to print their info to standard out
Naming matters too โจ Scripts should be named NN-xxxxxx, where NN is a two digit number that sets their position in the MOTD, and xxxxxx is a good name for what the script does ๐
Scripts must not have filename extensions, per the run-parts(8) --lsbsysinit instructions. no .sh for you, sorry not sorry ๐
โโ๏ธ
Packages should drop scripts directly into /etc/update-motd.d, not symlinks to other scripts. Why? So admins can modify or remove them and upgrades won't wipe their local changes ๐ฅบ A nice trick is a simple shell script that just calls exec on the external utility.
Long running operations (like network calls) or resource heavy scripts should cache their output and only refresh it when it's expired. Here's a cute example ๐
/etc/update-motd.d/50-news
#!/bin/sh
out=/run/foo
script="w3m -dump http://news.google.com/"
if [ -f "$out" ]; then
# Output exists, print it
echo
cat "$out"
# See if it's expired, and background update
lastrun=$(stat -c %Y "$out") || lastrun=0
expiration=$(expr $lastrun + 86400)
if [ $(date +%s) -ge $expiration ]; then
$script > "$out" &
fi
else
# No cache at all, so update in the background
$script > "$out" &
fi
Also, scripts should print a blank line before their output and end with a newline character โจ For instance:
/etc/update-motd/05-lsb-release
#!/bin/sh
echo
lsb-release -a
๐๏ธ FILES ๐๏ธ
/etc/motd, /run/motd.dynamic, /etc/update-motd.d
๐ SEE ALSO ๐
motd(5), pam_motd(8), run-parts(8) ๐
๐ AUTHOR ๐
This manpage and the update-motd framework were written by Dustin Kirkland <kirkland@canonical.com> for Ubuntu systems, but anyone else is welcome to use it ๐ Permission is granted to copy, distribute and/or modify this document under the terms of the GNU General Public License, Version 3, published by the Free Software Foundation.
On Debian systems, the full text of the GNU General Public License lives in /usr/share/common-licenses/GPL ๐
bye bestie, that's the whole update-motd tea โ๐ฆ source: update-motd, last updated 13 April 2010, and you now know more about this page than most people ever will ๐โจ
๐ฆ where this page comes from
- ubuntu noble: libpam-modules 1.5.3-5ubuntu5 ยท BSD-3-Clause OR GPL
- ubuntu noble: libpam-modules 1.5.3-5ubuntu5.7 ยท BSD-3-Clause OR GPL
- ubuntu questing: libpam-runtime 1.7.0-5ubuntu2 ยท BSD-3-Clause OR GPL
- ubuntu resolute: libpam-runtime 1.7.0-5ubuntu3 ยท BSD-3-Clause OR GPL
- ubuntu resolute: libpam-runtime 1.7.0-5ubuntu3.2 ยท BSD-3-Clause OR GPL
- ubuntu stonking: libpam-runtime 1.7.0-5ubuntu4 ยท BSD-3-Clause OR GPL
- ๐ girlified by anthropic/claude-haiku-5.5 on : a language model's rewrite of the original, under its terms