named pipes and .plan

Kaleb Keithley kaleb at thyme.jpl.nasa.gov
Fri Sep 28 09:12:28 AEST 1990


In article coleman at 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 at 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 at thyme.jpl.nasa.gov

Stirring up trouble again.



More information about the Comp.unix.programmer mailing list