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!
- Server Hardening
- EnterpriseDB's EDB Postgres Advanced Server and EDB Postgres Enterprise Manager
- The Death of RoboVM
- BitTorrent Inc.'s Sync
- The US Government and Open-Source Software
- The Humble Hacker?
- Open-Source Project Secretly Funded by CIA
- New Container Image Standard Promises More Portable Apps
- AdaCore's SPARK Pro
- ACI Worldwide's UP Retail Payments
In modern computer systems, privacy and security are mandatory. However, connections from the outside over public networks automatically imply risks. One easily available solution to avoid eavesdroppers’ attempts is SSH. But, its wide adoption during the past 21 years has made it a target for attackers, so hardening your system properly is a must.
Additionally, in highly regulated markets, you must comply with specific operational requirements, proving that you conform to standards and even that you have included new mandatory authentication methods, such as two-factor authentication. In this ebook, I discuss SSH and how to configure and manage it to guarantee that your network is safe, your data is secure and that you comply with relevant regulations.Get the Guide