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


UNIX Power Tools

UNIX Power ToolsSearch this book
Previous: 2.14 motd.diff: Show New Lines in Login Messages Chapter 2
Logging In
Next: 2.16 Approved Shells: Using Unapproved Login Shell
 

2.15 Unclutter Logins: Show Login Messages Just Once

Ignoring your system login messages because they're so long? You might miss something important some day. Here's a way to see the message, from the file /etc/motd , only if it's changed since the last time you read it. The ls option -t (16.2 ) sorts a list of files with the most recently modified file first. The following lines use a csh array (47.5 ) to store the output of ls -t comparing two files' modification times. If the /etc/motd file is newer than the ~/.hushlogin file, two commands are run. I use these lines in my .login file (2.2 ) , though they will work anywhere in the C shell:


set files=(`ls -t /etc/motd ~/.hushlogin`)
if ( $files[1] == /etc/motd ) then
    cat /etc/motd
    touch ~/.hushlogin
endif
unset files

NOTE: If you have ls aliased (10.2 ) to output anything but filenames (for instance, to print the sizes of files with -s ) you'll need to use the system version with /bin/ls instead of just ls .

This method uses the .hushlogin files on many UNIXes: if that file exists, the login process is quiet. We make .hushlogin do double duty by storing the current timestamp with touch (21.7 ) .

(This ls -t file-comparison technique will work on all UNIXes and it's useful any time you need to compare two files. You can use the same technique to mark the time that something has happened to any file - or to compare any two files or directories. Use the ls -d option (16.8 ) for directories.)

- JP


Previous: 2.14 motd.diff: Show New Lines in Login Messages UNIX Power Tools Next: 2.16 Approved Shells: Using Unapproved Login Shell
2.14 motd.diff: Show New Lines in Login Messages Book Index 2.16 Approved Shells: Using Unapproved Login Shell

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