home | O'Reilly's CD bookshelfs | FreeBSD | Linux | Cisco | Cisco Exam  


UNIX Power Tools

UNIX Power ToolsSearch this book
Previous: 2.13 A .cshrc.$HOST File for Per Host Setup Chapter 2
Logging In
Next: 2.15 Unclutter Logins: Show Login Messages Just Once
 

2.14 motd.diff: Show New Lines in Login Messages

One UNIX system I worked on had a really lonnnnnnnng login message that scrolled across my screen. It had a lot of old stuff that I'd seen for the last three weeks. For a while, I started ignoring it. But I knew that some day the system manager would put a shutdown notice in there that I wouldn't see...

This script solved the problem. I run it from my .login file. Each time I log in, the script compares the current /etc/motd file to the one on my previous login. If lines were added, I see them; the script pauses to give me time to read:

login: 

jpeek


Password:

Additions to system message-of-the-day:
===== 9/5/91 =====
The system will be down for maintenance from 9 to 11 tonight.
Hit RETURN to continue:

If there are no new lines, my login is nice and quiet.

motd.diff
This works best on systems that look for a file named .hushlogin in your home directory and don't print login messages if the file exists. [2] Install the program from the CD-ROM, then add the command motd.diff on a line in your .login or .profile .

[2] That also shuts off the message You have mail . But I always have mail, so I don't need that.  :-) If you do, and you use a command like Berkeley mail or mailx , add this line to your .login file:

if { mail -e } echo You have mail.

Those curly brace ( {} ) operators ( 47.4 ) work with the if ( 47.3 ) , to test the exit status ( 44.7 ) of mail -e . If mail -e returns zero ("success"), echo ( 8.6 ) prints You   have   mail.

motd.diff uses diff ( 28.1 ) to compare the system's current motd to the motd at your last login on that host (stored in a file named .last.motd. hostname in your home directory). The script finds whether lines have been added by grep ping for the character > at the start of each line of diff output:

diff $lastmotd /etc/motd > $temp
   ...
if grep "^>" $temp >/dev/null    # diff USES > TO MARK NEW LINES
then
   
...show lines...

The comm ( 28.12 ) command also shows lines that have been added to a file. But comm only handles sorted files; this trick works on unsorted files. The if ( 44.8 ) tests grep 's exit status ( 44.7 ) ( grep returns a zero status when it finds matching lines). grep 's output is "thrown away" into /dev/null ( 13.14 ) - some versions of grep have a -s ("silent") option to do the same thing.

This script is designed to work on networked filesystems where my same home directory is mounted on more than one computer. If your home directory isn't shared between computers, or if all systems have the same system messages, you can edit the script to delete the hostname variable and command.

- JP


Previous: 2.13 A .cshrc.$HOST File for Per Host Setup UNIX Power Tools Next: 2.15 Unclutter Logins: Show Login Messages Just Once
2.13 A .cshrc.$HOST File for Per Host Setup Book Index 2.15 Unclutter Logins: Show Login Messages Just Once

The UNIX CD Bookshelf Navigation The UNIX CD BookshelfUNIX Power ToolsUNIX in a NutshellLearning the vi Editorsed & awkLearning the Korn ShellLearning the UNIX Operating System