[comp.unix.programmer] named pipes and .plan

coleman@sunny.DAB.GE.COM (Richard Coleman) (09/26/90)

-- 
Could someone send me or post a simple example
of sending program output to .plan when someone uses
the finger command.  It would be greatly appreciated.


           Richard Coleman
           G.E. Simulation & Control Systems
           coleman@sunny.dab.ge.com

pfalstad@phoenix.Princeton.EDU (Paul John Falstad) (09/28/90)

In article <5932@ge-dab.GE.COM> coleman@sunny.DAB.GE.COM (Richard Coleman) writes:
>Could someone send me or post a simple example
>of sending program output to .plan when someone uses
>the finger command.  It would be greatly appreciated.

Somebody just posted an 100+ line program that does much the same thing as
this (unless I'm missing something really obvious):

nowhere% cd
nowhere% /usr/etc/mknod .plan p
nowhere% sh
$ while true; do (
> echo This is my .plan.
> /usr/games/fortune         # put whatever you want inside the ( )'s
> ) >.plan; sleep 1; done &
12345
$ exit
nowhere% cat .plan
This is my .plan.
Stupid, n.:
	Losing $25 on the game and $25 on the instant replay.

Also try this inside the plan:

echo Stop fingering me, `w|grep finger|awk '{print $1}'`

Now what am I missing??? Why does this have to be so complicated????

Paul Falstad, pfalstad@phoenix.princeton.edu PLink:HYPNOS GEnie:P.FALSTAD
I'd like to answer this question, if I may, in two ways.  Firstly in
my normal voice, and then in a kind of silly high-pitched whine.

kaleb@thyme.jpl.nasa.gov (Kaleb Keithley ) (09/28/90)

In article coleman@sunny.DAB.GE.COM (Richard Coleman) writes:
>-- 
>Could someone send me or post a simple example
>of sending program output to .plan when someone uses
>the finger command.  It would be greatly appreciated.
>
Here's the one I wrote as a result of this thread.  It does work,
feel free to finger me (kaleb@nutmeg.jpl.nasa.gov) if you doubt my
word.

It may not be the epitome of efficiency, so I'll gladly take tips
on making it better.

#include <time.h>
#include <sys/types.h>
#include <sys/time.h>
#include <fcntl.h>

main ()

{

    int     planfile;
    int     number = 0;
    time_t  tim;
    char    *planmessage = "You are the %d%s person to finger me\nat the tone, the time will be %s\n"; 
    char    target[256];
    char    *consmessage = "you have been fingered\n";
    char    *index2;

    for (;;) {

        planfile = open (".plan", O_WRONLY );

        time (&tim);
        switch (number % 10) {
            case 1: index2 = "st"; break;
            case 2: index2 = "nd"; break;
            case 3: index2 = "rd"; break;
            default: index2 = "th"; break;
        }
        sprintf (target,planmessage, number++, index2, asctime (localtime (&tim)));
        write (planfile, target, strlen (target));

        write (1, consmessage, strlen (consmessage));
        close (planfile);

        sleep (1);

    }
}
	

-- 
Kaleb Keithley                      Jet Propulsion Labs
kaleb@thyme.jpl.nasa.gov

Stirring up trouble again.

brnstnd@kramden.acf.nyu.edu (Dan Bernstein) (09/28/90)

In article <2884@idunno.Princeton.EDU> pfalstad@phoenix.Princeton.EDU (Paul John Falstad) writes:
> Somebody just posted an 100+ line program that does much the same thing as
> this (unless I'm missing something really obvious):
  [ shell script deleted ]
> Now what am I missing??? Why does this have to be so complicated????

Error checking, a couple of extra features, and no wasted execs. If you
don't want to check errors, write code for Berkeley. :-)

---Dan