Reading MOTD but only once. 
Author Message
 Reading MOTD but only once.

Archive-name: perl-source/dhesi/motd
Checksum: 3249094615 (verify with 'brik')

[ Following up discussion in comp.unix.programmer about how to see
/etc/motd only once. ]

#! /usr/bin/perl
#
# 1993/09/25


#
# If invoked as 'motd', warn user if /etc/motd was revised.
#
# If invoked as 'motd -i', initialize by copying motd file to
# .motd.$hostname.
#
# Separately, you should periodically run a find to delete old
# .motd.$hostname files that are older than a few weeks.

$home = $ENV{'HOME'} || die "Can't find environment variable HOME, stopped";

$hostname = `hostname`; chop $hostname;
$motd = "/etc/motd";
$hmotd = "$home/.motd.$hostname";


   system "cp $motd $hmotd";
   exit(0);

Quote:
}

if (-e $motd && -e $hmotd) {
   $status = system "cmp -s $motd $hmotd";
   if ($status != 0) {
      print "WARNING:  $motd changed \n";
      system "diff $hmotd $motd";
   }

Quote:
}

exit(0);


Thu, 14 Mar 1996 03:27:50 GMT  
 Reading MOTD but only once.
Quote:

>Archive-name: perl-source/dhesi/motd

>[ Following up discussion in comp.unix.programmer about how to see
>/etc/motd only once. ]

>#! /usr/bin/perl

[33 more lines of Perl deleted].

Although I use perl a lot, I think that as a wrapper for Unix tools the
shell should have been used in this case.  The following lines come from
my csh .login file:

set hostname = `hostname`
set fsname = `expr $hostname : '\([^0-9]*\)'`
if ! { cmp -s .hushlogin/$fsname /etc/motd } tee </etc/motd .hushlogin/$fsname

(I have directed followups to alt.sources.d)

Diomidis
--

Department of Computing, Imperial College, London SW7     #include "/dev/tty"



Thu, 14 Mar 1996 05:41:03 GMT  
 Reading MOTD but only once.

Quote:

>Archive-name: perl-source/dhesi/motd
>#! /usr/bin/perl

I use the following:

#!/usr/local/bin/bash
motd ()
{
        touch ~/.hushlogin
        more /etc/motd

Quote:
}

if [ -f ~/.hushlogin ] ; then
        if [ /etc/motd -nt ~/.hushlogin ] ; then
                motd
        fi
else
        motd
fi
--

723 Allison Ave, #8, Manhattan, KS  66502-3273
(913) 776-5789


Fri, 15 Mar 1996 22:58:16 GMT  
 Reading MOTD but only once.
:
: [ Following up discussion in comp.unix.programmer about how to see
: /etc/motd only once. ]
:
: .... perl program ...

Not that I don't think perl is the neatest thing since sliced bread,
but how about simply:

cmp -s $HOME/.llog /etc/motd || (cat /etc/motd | tee $HOME/.llog)
--

                UUCP:   ...!uunet!tektronix!Roger.S.Southwick



Sat, 16 Mar 1996 00:50:55 GMT  
 Reading MOTD but only once.

Quote:
>Not that I don't think perl is the neatest thing since sliced bread,
>but how about simply:
>cmp -s $HOME/.llog /etc/motd || (cat /etc/motd | tee $HOME/.llog)

Too simplistic...if you log into host A and see its /etc/motd, then
log into host B, you might miss an update on B.  An improvement
would be:

   cmp -s $HOME/.motd.`hostname` /etc/motd ||
      (cat /etc/motd | tee $HOME/.motd.`hostname`)

This is still not as good as the original per script, because it shows
you the entire /etc/motd even if only one line changed.  There are
systems on which /etc/motd is essentially the sysadmin's autobiography,
and you want to avoid reading *that* too often.
--




Sat, 16 Mar 1996 02:50:36 GMT  
 Reading MOTD but only once.
In my C-Shell login, I use:

        find /etc/motd -newer ~/.hushlogin -exec cat {} \; ; touch ~/.hushlogin

Saves sysadmins from having copies of motd all over the place.  A
mod for multiple hosts is trivial:

        find /etc/motd -newer ~/.hush`hostname` -exec cat {} \; ; touch ~/.hush`hostname`

--
David F. Skoll



Sat, 16 Mar 1996 03:22:19 GMT  
 Reading MOTD but only once.

Quote:
>In my C-Shell login, I use:
>        find /etc/motd -newer ~/.hushlogin -exec cat {} \; ; touch ~/.hushlogin
>Saves sysadmins from having copies of motd all over the place.  A
>mod for multiple hosts is trivial:
>    find /etc/motd -newer ~/.hush`hostname` -exec cat {} \; ; touch ~/.hush`hostname`
>--
>David F. Skoll

I appreciate everybody's help although my sysadmin mailed me one that is
exactly like the one here.  I like this one the best for it's simplicity.
Thanks again,

-- DaviD



Sat, 16 Mar 1996 04:18:26 GMT  
 Reading MOTD but only once.

Quote:

>    cmp -s $HOME/.motd.`hostname` /etc/motd ||
>       (cat /etc/motd | tee $HOME/.motd.`hostname`)

> This is still not as good as the original per script, because it shows
> you the entire /etc/motd even if only one line changed.  There are
> systems on which /etc/motd is essentially the sysadmin's autobiography,
> and you want to avoid reading *that* too often.

I've had this in my .login just about forever.  It show additions
to the motd since this was last run.

  diff $HOME/.last_motd.`hostname` /etc/motd | grep '^> ' | sed 's/^> //'
  cp /etc/motd $HOME/.last_motd.`hostname`

Looking at it now, it can be cleaned up to use perl and become:

  diff ~/.last_motd.`hostname` /etc/motd | perl -ne 'print if s/^> (.*)/\1/'
  cp /etc/motd $HOME/.last_motd.`hostname`

Tom

--


University of Pittsburgh Medical Center   Phone:    +1 412 681-3482        
WPIC Drug and {*filter*} Epidemiology        FAX:      +1 412 681-1261



Sat, 16 Mar 1996 07:05:11 GMT  
 Reading MOTD but only once.
Here is how to do it when your home dir may be mounted from many
different hosts.  This can also be used on a single host, to achieve
the same result without extra files (except .hushlogin):

In .login, add the line:

make -f .hushlogin .Hosts/motd.$HOST

(I find having a .Hosts directory is quite useful in the multiple-host
single-home situation).

Now, .hushlogin is a makefile-style file containing:

$HOST = $$HOST

.Hosts/motd.$(HOST): /etc/motd




In a single-host situation, just change .Hosts/motd.$(HOST) to .hushlogin.

--

Paper: The Hebrew Univ. of Jerusalem, Dept. of Comp. Science.
       Givat-Ram, Jerusalem 91904, Israel



Sat, 16 Mar 1996 17:24:29 GMT  
 Reading MOTD but only once.

Why not just find source for System V's "news" program?

That's what we did--allows you to create a "news" directory of
items that users will only see once.
--

                                But that's ok...



Tue, 19 Mar 1996 08:48:47 GMT  
 Reading MOTD but only once.
: Why not just find source for System V's "news" program?
:
: That's what we did--allows you to create a "news" directory of
: items that users will only see once.

And, if it must be Perl (the header suggests so), I've written a 'news' in
Perl. It's at neutron.chem.yale.edu in /pub/news.tar.Z.

Cheers,

--

| Lab phone: 203-432-5208     Fax: 203-432-6144    Home phone: 203-624-3866 |
| For complying with the NJ Right To Know Act:  Contents partially unknown. |



Tue, 19 Mar 1996 21:13:08 GMT  
 Reading MOTD but only once.

Quote:

> I've had this in my .login just about forever.  It show additions
> to the motd since this was last run.

>   diff $HOME/.last_motd.`hostname` /etc/motd | grep '^> ' | sed 's/^> //'
>   cp /etc/motd $HOME/.last_motd.`hostname`

> Looking at it now, it can be cleaned up to use perl and become:

>   diff ~/.last_motd.`hostname` /etc/motd | perl -ne 'print if s/^> (.*)/\1/'
>   cp /etc/motd $HOME/.last_motd.`hostname`

CLEANED UP!!!!!  Excuse me for shouting, but could someone please
explain to me just excactly how replacing two relatively tiny
utilities in the original pipeline with the monster perl binary is
"cleaning" this example up?!?!??!?!??  [Never mind the reversal of
common programming logic required to understand that one minor line of
perl code....]

I'm sure that the entire thing could be compressed into a few measly
lines of perl code, thus eliminating the entire pipeline, and the
subsequent copy command too, but I, for one, sure as hell don't want
to have to invoke perl in my .profile (at least not on any system that
I regularly use today -- even a Sparc 10 has second thoughts about
instantaneously running the average perl script).

IMHO, such applications of perl are a big, ugly, non-portable (i.e.
won't work on any system that doesn't have a working copy of perl),
and an un-neccesary waste of memory and cpu cycles.

FYI, I use the same .profile on *every* system I run across, and it'll
work just as well on a freshly installed system as it will on an
enormously hacked system.  It'll even work (though with reduced
results) on a system in single-user mode and nothing mounted but /.
--
                                                Greg A. Woods


+1 416 443-1734 [home]                          Toronto, Ontario; CANADA



Tue, 19 Mar 1996 13:55:27 GMT  
 Reading MOTD but only once.



| > I've had this in my .login just about forever.  It show additions
| > to the motd since this was last run.
| >
| >   diff $HOME/.last_motd.`hostname` /etc/motd | grep '^> ' | sed 's/^> //'
| >   cp /etc/motd $HOME/.last_motd.`hostname`
| >
| > Looking at it now, it can be cleaned up to use perl and become:
| >
| >   diff ~/.last_motd.`hostname` /etc/motd | perl -ne 'print if s/^> (.*)/\1/'
| >   cp /etc/motd $HOME/.last_motd.`hostname`
|
| CLEANED UP!!!!!  Excuse me for shouting, but could someone please
| explain to me just excactly how replacing two relatively tiny
| utilities in the original pipeline with the monster perl binary is
| "cleaning" this example up?!?!??!?!??

For that matter, the grep and the sed can be replaced with one call to sed
instead of perl, reducing the overhead further:

   diff $HOME/.last_motd.`hostname` /etc/motd | sed -n 's/^> //p'
   cp /etc/motd $HOME/.last_motd.`hostname`

Sometimes a pair of scissors will do the job and you don't need to get out
the chainsaw.

David W. Tamkin  Box 3284  Skokie, Illinois  60076-6284  312-714-5610



Wed, 20 Mar 1996 11:25:27 GMT  
 Reading MOTD but only once.


:

: | > I've had this in my .login just about forever.  It show additions
: | > to the motd since this was last run.
: | >
: | >   diff $HOME/.last_motd.`hostname` /etc/motd | grep '^> ' | sed 's/^> //'
: | >   cp /etc/motd $HOME/.last_motd.`hostname`
: | >
: | > Looking at it now, it can be cleaned up to use perl and become:
: | >
: | >   diff ~/.last_motd.`hostname` /etc/motd | perl -ne 'print if s/^> (.*)/\1/'
: | >   cp /etc/motd $HOME/.last_motd.`hostname`
: |
: | CLEANED UP!!!!!  Excuse me for shouting, but could someone please
: | explain to me just excactly how replacing two relatively tiny
: | utilities in the original pipeline with the monster perl binary is
: | "cleaning" this example up?!?!??!?!??
:
: For that matter, the grep and the sed can be replaced with one call to sed
: instead of perl, reducing the overhead further:
:
:    diff $HOME/.last_motd.`hostname` /etc/motd | sed -n 's/^> //p'
:    cp /etc/motd $HOME/.last_motd.`hostname`

I wouldn't use Perl for that either.

: Sometimes a pair of scissors will do the job and you don't need to get out
: the chainsaw.

I have no problem with that.  I do have a bit of a problem when
someone provides a chainsaw followup to a little twig of suboptimal
choice, especially when it was tendered as an olive twig.  Hot button
getting a bit sticky of late, Greg?

Okay, I'll admit it.  My hot button is seeing someone get their
head bitten off for doing what they thought was right.

Larry



Wed, 20 Mar 1996 16:26:04 GMT  
 Reading MOTD but only once.


:> I've had this in my .login just about forever.  It show additions
:> to the motd since this was last run.
:>
:>   diff $HOME/.last_motd.`hostname` /etc/motd | grep '^> ' | sed 's/^> //'
:>   cp /etc/motd $HOME/.last_motd.`hostname`
:>
:> Looking at it now, it can be cleaned up to use perl and become:
:>
:>   diff ~/.last_motd.`hostname` /etc/motd | perl -ne 'print if s/^> (.*)/\1/'
:>   cp /etc/motd $HOME/.last_motd.`hostname`
:
:CLEANED UP!!!!!  Excuse me for shouting, but could someone please
:explain to me just excactly how replacing two relatively tiny
:utilities in the original pipeline with the monster perl binary is
:"cleaning" this example up?!?!??!?!??  [Never mind the reversal of
:common programming logic required to understand that one minor line of
:perl code....]

I certainly hope you feel better.

He doesn't see why to use two programs instead of one.  Neither do
I.  People do the same thing with awk as well.  

Now personally, I happen to use "make -f .hushlogin" myself as I wrote
in the UNIX Power Tools book, but I certainly don't mind calling perl
whenever it trips my trigger.  The machine is there to do my bidding,
and it shall.

On a cold, non-primed up *tiny* and *slow* Sun ELC system,

    time perl -e 'print "hello world\n"
    0.040u 0.200s 0:00.35 68.5% 0+297k 3+6io 2pf+0w

It doesn't annoy me, and it probably didn't annoy Tom Link.
I'm sorry it annoys you.

--tom
--

                    Consultant
        Boulder Colorado  303-444-3212



Wed, 20 Mar 1996 14:53:15 GMT  
 
 [ 16 post ]  Go to page: [1] [2]

 Relevant Pages 

1. Reading from <DATA> more than once

2. using motd to make Perl style comments

3. MOTD web script?

4. Module development: once is enough

5. Working with two streams at once: ack pth!

6. match all but once?

7. Multiple dbmopen()'s at once (perl4)

8. Alias::const: avoiding `used only once...' warning

9. alarm only works once???

10. Once again: CGI help

11. regexp to negate 2 chars at once

12. Matching two patterns at once

 

 
Powered by phpBB® Forum Software