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.
Fast/Flexible Linux OS Recovery
On Demand Now
In this live one-hour webinar, learn how to enhance your existing backup strategies for complete disaster recovery preparedness using Storix System Backup Administrator (SBAdmin), a highly flexible full-system recovery solution for UNIX and Linux systems.
Join Linux Journal's Shawn Powers and David Huffman, President/CEO, Storix, Inc.
Free to Linux Journal readers.Register Now!
- Download "Linux Management with Red Hat Satellite: Measuring Business Impact and ROI"
- 2005 Linux Journal Readers' Choice Awards
- Kbuild: the Linux Kernel Build System
- Linux Mint 18
- Sony Settles in Linux Battle
- Introduction to Named Pipes
- Experimenting with New Methods in Voice over IP
- Advanced Packet Data Testing with Linux
- Overcoming Asymmetric Routing on Multi-Homed Servers
- Supercat Text Colorizer
With all the industry talk about the benefits of Linux on Power and all the performance advantages offered by its open architecture, you may be considering a move in that direction. If you are thinking about analytics, big data and cloud computing, you would be right to evaluate Power. The idea of using commodity x86 hardware and replacing it every three years is an outdated cost model. It doesn’t consider the total cost of ownership, and it doesn’t consider the advantage of real processing power, high-availability and multithreading like a demon.
This ebook takes a look at some of the practical applications of the Linux on Power platform and ways you might bring all the performance power of this open architecture to bear for your organization. There are no smoke and mirrors here—just hard, cold, empirical evidence provided by independent sources. I also consider some innovative ways Linux on Power will be used in the future.Get the Guide