Tech Tip: Periodically Update Your MOTD with update-motd
This tech tip provides you with information on how to customize your motd (Message Of The Day) message to display the output of one or more scripts. This uses the update-motd package, which updates the motd message when run. I use this method on Ubuntu 9.10, but not all systems provide this package so extra effort may be required to use it on other systems.
The update-motd daemon can be installed with:
$ sudo apt-get install update-motd
How update-motd operates depends on the version of update-motd that you have installed but the net effect is that it runs a set of scripts whose output is concatenated to produce a new motd message.
If you navigate to /etc/update-motd.d/ you will notice that there are a series of pre-defined scripts that begin with numbers and a hyphen. The numbers tell update-motd which script to run first (from lowest to highest) and in what order to display them on the output. If you’d like, you can either create a new script or add your commands to one of the existing scripts.
In my case, the script that displays my information is "10-stats", it contains:
#!/bin/bash
echo " ======================================="
echo " = Welcome to FSERV1. ="
echo " ======================================="
echo
btime=`who -b | sed -e 's/[^A-Z]*//'`
utime=`uptime | sed -e 's/ [0-9:]* up />/' -e 's/,.*//'`
echo " ==== BOOT TIME ==== ==== UPTIME ===="
echo " "$btime" " $utime
echo
echo "===================== DISK USAGE ======================"
df -h | egrep '(Filesystem)|(/dev/sd)'
echo
echo "================== CURRENTLY ONLINE ==================="
echo "NAME LINE TIME IP ADDRESS"
who –ips
In my case I’ve chosen to have the script display the date and time the system was booted (using who -b), the system uptime, disk usage information, and who is currently logged onto the system. To get the output as I want it I use sed to extract the pieces I want to output. The sed command is used to edit text, this does require some basic knowledge of regular expressions, a subject that could and has filled volumes.
The system uptime is derived from the command line:
utime=`uptime | sed -e 's/ [0-9:]* up />/' -e 's/,.*//'`
The full output from uptime would be something like:
10:19:47 up 375 days, 9:20, 4 users, load average: 0.93, 0.90, 0.81
I use sed to narrow it down to something like ">32 days". The -e specifies a sed "script" to use, I specify two scripts:
- s/ [0-9:]* up />/ - This replaces any repeated sequence of the characters "0 through 9 or a colon" ending in " up " with ">".
- s/,.*// - This replaces the first instance of a comma and any and all characters after it with a blank string (ie it wipes it out).
Note that the exact format of the output from uptime can differ across systems so this command could require some modifications.
When you’re done with your script, make sure to make it executable with chmod +x, now when you log in you should see your new motd message. Here's the output from my 10-stats script:
The hard drive stats I think are most critical. Every time I log in I can see where I stand with free space and migrate my data when necessary.
As I mentioned I use this method on Ubuntu 9.10, but not all systems provide the update-motd package and the version of the package you use can also affect the details of its operation, but the basic feature is the same: it gives you the ability to periodically change your motd message.
| Attachment | Size |
|---|---|
| motd-1.png | 4.4 KB |
| motd-2.png | 8.2 KB |
Trending Topics
| You Need A Budget | Feb 10, 2012 |
| The Linux powered LAN Gaming House | Feb 08, 2012 |
| Creating a vDSO: the Colonel's Other Chicken | Feb 06, 2012 |
| Your CMS Is Not Your Web Site | Feb 01, 2012 |
| Casper, the Friendly (and Persistent) Ghost | Jan 31, 2012 |
| Razor-qt 0.4 - Qt based Desktop Environment | Jan 30, 2012 |
- Linux-Based X Terminals with XDMCP
- Readers' Choice Awards 2011
- 100% disappointed with the decision to go all digital.
- Parallel Programming with NVIDIA CUDA
- You Need A Budget
- Validate an E-Mail Address with PHP, the Right Way
- Python for Android
- The Linux RAID-1, 4, 5 Code
- The Linux powered LAN Gaming House
- RSS Feeds
- Gnome3 is such a POS. No one
2 min 11 sec ago - Gnome 3 is the biggest POS
12 min 48 sec ago - I didn't knew this thing by
6 hours 17 min ago - Author's reply
9 hours 41 min ago - Link to modlys
10 hours 48 min ago - I use YNAB because of the
10 hours 59 min ago - Search
16 hours 2 min ago - Question
16 hours 25 min ago - for the record
16 hours 28 min ago - That's disappointing. Thanks
18 hours 51 min ago





Comments
$ who -b|awk '{print $3 " "
$ who -b|awk '{print $3 " " $4}'
2009-12-23 08:15
... looks cleaner to me.
hi, who is the developer of
hi,
who is the developer of that stuff?
i googled for it but i cant find any development-portal or any infos about the devolpers in the web, just some ubuntu related stuff.
i want to port that stuff for redhat and fedora but i dont want to "fork" it just from some install packages. cvs? anyone?
thanks
anton
Developer
Check the man page it has the developer's name and email address.
Mitch Frazier is an Associate Editor for Linux Journal.
Nice. Except that you don't
Nice. Except that you don't need update-modt to get there. I've been doing something similar for years simply putting all that in rc.local and generating the motd on the fly from header and various parts (just like my .sig).
Also remember motd is for people login in text mode only. for those loging directly into X you need xmessage or better still notification daemon (or use issue, built on the fly also).
Cheers
script problem...
Not giving the btime? When I ran this script (just from a bash script),
I get the following output...
======================================= = Welcome to FSERV1. = ======================================= ==== BOOT TIME ==== ==== UPTIME ==== >59 min ===================== DISK USAGE ====================== Filesystem Size Used Avail Use% Mounted on /dev/sda3 192G 71G 112G 39% / ================== CURRENTLY ONLINE =================== NAME LINE TIME IP ADDRESSBoot Time
When I run "who -b" I get the following output:
system boot 2008-12-04 01:24The following would extract the correct data:
Or you could use:
Mitch Frazier is an Associate Editor for Linux Journal.
Anonymous: What distribution
Anonymous:
What distribution are you using? You should no doubt get output when typing "who -b" in the command line. Try running the the command in a console without assigning it to a variable and see what your output is. As stated, the output may vary from system to system and you will have to modify it if needed. Let us know what the output is.