
When you log on to a Linux system, you're presented with a Message of the Day (MOTD). In early versions, this was a static message, read from a single file, but with recent releases of Ubuntu and other variations of Linux, it now contains dynamic information generated from a set of scripts. The idea behind the MOTD is to show SSH users pertinent information about the system and other policies that may govern usage of the system.
The default MOTD looks somewhat like this:
The information comes from various scripts located in /etc/update-modt.d/ and the /etc/legal file. The scripts execute based on the first two digits of the name. 14 scripts make up the default MOTD. The motd-news service controls the data and its updates.
The MOTD also imports news from a remote URL, controlled by /etc/default/motd-news. To disable dynamic news, edit this file and change ENABLED=1 to ENABLED=0
To disable the MOTD on a per user basis, add a blank file to the home directory of the user. Name the file .hushlogin. Create it by running:
and the MOTD stops showing when the specific user logs in.
To remove pieces of the MOTD, you can delete the corresponding script in /etc/update-motd.d/ or set the execute bit to off by running chmod -x followed by the script name.
Adding your own message of the day is easy. Create a file in /etc/update-motd.d/. The filename must be two digits followed by a hyphen and then a common name or reference for your script. Files should not contain an extension. The file can be any executable type your system is capable of running, usually defined by the she bang on the first line.
To make the message of the day fun, add a Chuck Norris quote. The example uses PHP as the scripting language.
Add PHP scripting capabilities:
Disable all other MOTD scripts
Create a new script:
Add code to retrieve a quote from the public API containing Chuck Norris quotes:
The script retrieves a random JSON payload, places it in to a JSON array and then prints a new line above and below the quote.
Ensure the script has the execute bit flipped:
Log out and log back in and you should see a random Chuck Norris quote in your message of the day.
The flexibility of dynamic message of the day provides lots of options. Enable or disable certain scripts to show load, users, package, required reboots, or even create your own custom scripts to display pertinent information or custom text related to your environment or system and user base.
0 Comments
Be the first to comment and share your perspective with the community.