2.15 Unclutter Logins: Show Login Messages Just OnceIgnoring 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
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.) - |
|