home *** CD-ROM | disk | FTP | other *** search
/ Source Code 1994 March / Source_Code_CD-ROM_Walnut_Creek_March_1994.iso / compsrcs / misc / volume39 / planner / part01 < prev    next >
Encoding:
Text File  |  1993-08-23  |  25.2 KB  |  753 lines

  1. Newsgroups: comp.sources.misc
  2. From: franklin@ug.cs.dal.ca (Steve Franklin)
  3. Subject: v39i048: planner - Named pipe for random .plan or .signature, Part01/01
  4. Message-ID: <1993Aug23.042125.27928@sparky.sterling.com>
  5. X-Md4-Signature: f8be4a0379c069919c0f21ccbe41370f
  6. Sender: kent@sparky.sterling.com (Kent Landfield)
  7. Organization: Math, Stats & CS, Dalhousie University, Halifax, NS, Canada
  8. Date: Mon, 23 Aug 1993 04:21:25 GMT
  9. Approved: kent@sparky.sterling.com
  10.  
  11. Submitted-by: franklin@ug.cs.dal.ca (Steve Franklin)
  12. Posting-number: Volume 39, Issue 48
  13. Archive-name: planner/part01
  14. Environment: Finger
  15.  
  16. The following is the best implementation of a named pipe I have yet
  17. found. It can be used for generating a random .plan, .signature, 
  18. etc. It has been modified and improved upon by a number of authors, 
  19. and I have seen fit to repackage it with a simplistic means of
  20. installation, and a cool trick or two. I hope that people will use
  21. it wisely, because it can mess up machines (read docs) if you use it
  22. improperly. 
  23.  
  24.    Direct questions to franklin@ug.cs.dal.ca
  25.    Hope you find it interesting...
  26.  
  27. Steve
  28. ---
  29. #! /bin/sh
  30. # This is a shell archive.  Remove anything before this line, then feed it
  31. # into a shell via "sh file" or similar.  To overwrite existing files,
  32. # type "sh file -c".
  33. # Contents:  README Makefile lf logfinger plan.1 plan.c plan.header
  34. #   planner readme.orig renewplan
  35. # Wrapped by kent@sparky on Sun Aug 22 23:14:07 1993
  36. PATH=/bin:/usr/bin:/usr/ucb:/usr/local/bin:/usr/lbin ; export PATH
  37. echo If this archive is complete, you will see the following message:
  38. echo '          "shar: End of archive 1 (of 1)."'
  39. if test -f 'README' -a "${1}" != "-c" ; then 
  40.   echo shar: Will not clobber existing file \"'README'\"
  41. else
  42.   echo shar: Extracting \"'README'\" \(3158 characters\)
  43.   sed "s/^X//" >'README' <<'END_OF_FILE'
  44. XSteve Franklin  (not the original author)
  45. Xfranklin@ug.cs.dal.ca
  46. XCompiled on August 8th, 1993
  47. X
  48. XBefore I continue by describing what all of this does, I should point out that
  49. XI am not the original author of this software. I have modified it like
  50. Xmany before me and am now trying to simplify the documentation as so many
  51. Xusers have requested.
  52. X
  53. XPurpose: The purpose of namedp is to create an ultra cool .plan file so
  54. X         that people can get random .plan's when they finger you. It
  55. X         can be used in a variety of ways, and depending on how creative
  56. X         you are, can make you rich beyond your wildest dreams (well, sorta)
  57. X
  58. XContents:   Makefile      Self-explanatory - type "make" to compile
  59. X            logfinger     Hardly changed this - perl script to log whos fingering
  60. X            lf            Short script to let you know when you were last fin'd
  61. X            plan.1        Man page
  62. X            plan.c        C-code for the plan application
  63. X            planner       Shell script that shows a couple of neat tricks
  64. X            readme.orig   Original read me that was getting a tad "congested"
  65. X            renewplan     Script for starting up plan cleanly.
  66. X
  67. XChanges: The original plan seemed quite concerned with who was fingering you 
  68. X         from your local machine, but just logged "somebody" as fingering
  69. X         you if it was from another machine. All it took was a few additions
  70. X         (a la netstat) to let you figure out which machine is fingering you
  71. X         and a few more changes to impress the fingerer by letting them
  72. X         know their hostname. These settings are recorded into a file that
  73. X         you can later query.
  74. X
  75. XRequirements:  In order to run plan, you need bsd-ish architecture. Users
  76. X               running ULTRIX are out of luck, as are VMS users of course.
  77. X
  78. XInstructions:  The simplest way to sort through this is to first edit
  79. X               "planner","renewplan" and "logfinger" to resemble your environ.
  80. X               and your preferences. Then, place plan and renewplan in 
  81. X               your bin directory or any dir that your $PATH variable points 
  82. X               to. Simply type "renewplan" and it does the rest for you.
  83. X
  84. XQuestions:     Feel free to send questions to franklin@ug.cs.dal.ca
  85. X               but please try to read through all the documentation as well.
  86. X
  87. XCautions:      If your machine reboots, you will have an empty named pipe
  88. X               pointing at no process (it doesn't exist since the machine 
  89. X               rebooted). So, you have to restart the plan process (renewplan)
  90. X               after a reboot. If you don't catch it, people's finger 
  91. X               processes will clog up your finger port. To get around this
  92. X               I had an "at + 1 hour..." included in "renewplan" to re-exec
  93. X               renewplan every hour - if there was a reboot, plan would
  94. X               start up no more than an hour after the reboot. 
  95. X
  96. XExample:       Check out franklin@ug.cs.dal.ca for an example of how the
  97. X               namedp pipe can be used - hopefully it's up and running :)
  98. X               Hopefully you guys will mail me if you get neat ideas of
  99. X               your own...
  100. END_OF_FILE
  101.   if test 3158 -ne `wc -c <'README'`; then
  102.     echo shar: \"'README'\" unpacked with wrong size!
  103.   fi
  104.   # end of 'README'
  105. fi
  106. if test -f 'Makefile' -a "${1}" != "-c" ; then 
  107.   echo shar: Will not clobber existing file \"'Makefile'\"
  108. else
  109.   echo shar: Extracting \"'Makefile'\" \(1401 characters\)
  110.   sed "s/^X//" >'Makefile' <<'END_OF_FILE'
  111. XDEST          = /home/napalm/bin/fifo
  112. X
  113. XEXTHDRS          = /usr/include/fcntl.h \
  114. X        /usr/include/signal.h \
  115. X        /usr/include/stdio.h \
  116. X        /usr/include/sys/fcntl.h \
  117. X        /usr/include/sys/file.h \
  118. X        /usr/include/sys/stat.h \
  119. X        /usr/include/sys/sysmacros.h \
  120. X        /usr/include/sys/sysmacros.h \
  121. X        /usr/include/sys/types.h \
  122. X        /usr/include/sys/types.h
  123. X
  124. XHDRS          =
  125. X
  126. XLDFLAGS          =
  127. X
  128. XLIBS          =
  129. X
  130. XLINKER          = cc
  131. X
  132. XMAKEFILE      = Makefile
  133. X
  134. XOBJS          = plan.o
  135. X
  136. XPRINT          = pr
  137. X
  138. XPROGRAM          = plan
  139. X
  140. XSRCS          = plan.c
  141. X
  142. Xall:        $(PROGRAM)
  143. X
  144. X$(PROGRAM):     $(OBJS) $(LIBS)
  145. X        @echo -n "Loading $(PROGRAM) ... "
  146. X        @$(LINKER) $(LDFLAGS) $(OBJS) $(LIBS) -o $(PROGRAM)
  147. X        @echo "done"
  148. X
  149. Xclean:;        @rm -f $(OBJS)
  150. X
  151. Xdepend:;    @mkmf -f $(MAKEFILE) PROGRAM=$(PROGRAM) DEST=$(DEST)
  152. X
  153. Xindex:;        @ctags -wx $(HDRS) $(SRCS)
  154. X
  155. Xinstall:    $(PROGRAM)
  156. X        @echo Installing $(PROGRAM) in $(DEST)
  157. X        @install -s $(PROGRAM) $(DEST)
  158. X
  159. Xprint:;        @$(PRINT) $(HDRS) $(SRCS)
  160. X
  161. Xprogram:        $(PROGRAM)
  162. X
  163. Xtags:           $(HDRS) $(SRCS); @ctags $(HDRS) $(SRCS)
  164. X
  165. Xupdate:        $(DEST)/$(PROGRAM)
  166. X
  167. X$(DEST)/$(PROGRAM): $(SRCS) $(LIBS) $(HDRS) $(EXTHDRS)
  168. X        @make -f $(MAKEFILE) DEST=$(DEST) install
  169. X###
  170. Xplan.o: /usr/include/sys/types.h /usr/include/sys/sysmacros.h \
  171. X    /usr/include/sys/sysmacros.h /usr/include/sys/file.h \
  172. X    /usr/include/sys/fcntl.h /usr/include/sys/types.h \
  173. X    /usr/include/fcntl.h /usr/include/stdio.h /usr/include/sys/stat.h \
  174. X    /usr/include/signal.h
  175. END_OF_FILE
  176.   if test 1401 -ne `wc -c <'Makefile'`; then
  177.     echo shar: \"'Makefile'\" unpacked with wrong size!
  178.   fi
  179.   # end of 'Makefile'
  180. fi
  181. if test -f 'lf' -a "${1}" != "-c" ; then 
  182.   echo shar: Will not clobber existing file \"'lf'\"
  183. else
  184.   echo shar: Extracting \"'lf'\" \(224 characters\)
  185.   sed "s/^X//" >'lf' <<'END_OF_FILE'
  186. X#!/bin/sh
  187. Xtimeit=`ls -l /users/students/franklin/.dots/.fingerees | cut -c42-54`
  188. Xuser=`tail -2 /users/students/franklin/.dots/.fingerees | head -1 | cut -c1-8 | tr "," " "`
  189. Xecho "you were last fingered at:" $timeit by $user
  190. END_OF_FILE
  191.   if test 224 -ne `wc -c <'lf'`; then
  192.     echo shar: \"'lf'\" unpacked with wrong size!
  193.   fi
  194.   chmod +x 'lf'
  195.   # end of 'lf'
  196. fi
  197. if test -f 'logfinger' -a "${1}" != "-c" ; then 
  198.   echo shar: Will not clobber existing file \"'logfinger'\"
  199. else
  200.   echo shar: Extracting \"'logfinger'\" \(603 characters\)
  201.   sed "s/^X//" >'logfinger' <<'END_OF_FILE'
  202. X#!/usr/bin/perl -- # -*-Perl-*-
  203. X
  204. X$me = "franklin";
  205. X$logfile = "/users/students/franklin/.fingerees";
  206. X$pscommand = "ps -auw";
  207. X
  208. Xopen(PS, "$pscommand |");
  209. X@fingers = grep(/(f\s+$me)|(finger\s+$me)/, <PS>);
  210. Xclose(PS);
  211. X
  212. X($num) = unpack("A9", `wc -l $logfile`); # =~ s/^\s*(\d+).*\n/\1/;
  213. X($num2) = $num/2;
  214. Xprintf "I have been fingered %d time", $num2;
  215. Xprint "s" if ($num - 1);
  216. Xprint " today\n";
  217. Xclose(STDOUT);
  218. X
  219. Xopen(LOG, ">>$logfile");
  220. Xforeach $line (@fingers) {
  221. X    ($user) = $line =~ /^\s*(\S+)/;
  222. X    print LOG "$user, at ", `date`;
  223. X}
  224. X
  225. Xprint(LOG "somebody, at ", `date`) if (! ($#fingers + 1));
  226. Xclose(LOG);
  227. END_OF_FILE
  228.   if test 603 -ne `wc -c <'logfinger'`; then
  229.     echo shar: \"'logfinger'\" unpacked with wrong size!
  230.   fi
  231.   chmod +x 'logfinger'
  232.   # end of 'logfinger'
  233. fi
  234. if test -f 'plan.1' -a "${1}" != "-c" ; then 
  235.   echo shar: Will not clobber existing file \"'plan.1'\"
  236. else
  237.   echo shar: Extracting \"'plan.1'\" \(1495 characters\)
  238.   sed "s/^X//" >'plan.1' <<'END_OF_FILE'
  239. X.TH PLAN L "\*(V)" "4BSD"
  240. X.SH NAME
  241. Xplan - run an executable when a specified FIFO is opened
  242. X.SH SYNOPSIS
  243. X.B plan
  244. X[
  245. X.BR -f file
  246. X]
  247. X.B executable
  248. X.SH DESCRIPTION
  249. X.I plan
  250. Xtakes the name of an executable program and runs it on a FIFO that
  251. Xis specified on the command line or on a FIFO in the user's home directory
  252. Xnamed .plan.  Whenever the FIFO is accessed, the output of the executable
  253. Xprogram goes to the FIFO.  It also writes the PID of plan to a file, so
  254. Xthe process can be killed during logout, and it checks for the existence
  255. Xof this file to make sure plan isn't already running.
  256. X.SH OPTIONS
  257. X.TP
  258. X.B \-f file_name
  259. XThe \fB\-f flag causes \fIplan\fR to set up the specified \fBfile_name\fR
  260. Xas a FIFO rather than the default \fB$HOME/.plan\fR.
  261. X.PP
  262. XSome sample uses of \fIplan\fR would be:
  263. X.TP
  264. X.B plan /usr/games/fortune &
  265. XThis will display a randomly selected fortune as the contents of
  266. Xyour .plan file whenever you are fingered.
  267. X.TP
  268. X.B plan -f ~/.signature ~/bin/gensig &
  269. XThis will run the program gensig whenever your .signature file is accessed,
  270. Xallowing you to change your .signature whenever you post.
  271. X.TP
  272. X.B plan ~/bin/logfinger &
  273. XThis will run the program logfinger whenever your .plan file is accessed,
  274. Xand you can log all instances of people fingering you.
  275. X.SH AUTHOR
  276. XTony Rems (rembo@unisoft.com)
  277. X.PP
  278. XModifications by Geoff Loker (geoff@mdms.moore.com)
  279. XMore modifications by Karen Bruner (napalm@ugcs.caltech.edu)
  280. X.SH BUGS
  281. XYour system must support named pipes in order for this to work.
  282. END_OF_FILE
  283.   if test 1495 -ne `wc -c <'plan.1'`; then
  284.     echo shar: \"'plan.1'\" unpacked with wrong size!
  285.   fi
  286.   chmod +x 'plan.1'
  287.   # end of 'plan.1'
  288. fi
  289. if test -f 'plan.c' -a "${1}" != "-c" ; then 
  290.   echo shar: Will not clobber existing file \"'plan.c'\"
  291. else
  292.   echo shar: Extracting \"'plan.c'\" \(5034 characters\)
  293.   sed "s/^X//" >'plan.c' <<'END_OF_FILE'
  294. X
  295. X/*    THIS IS THE UNPUBLISHED SOURCE CODE OF REMBO        */
  296. X/*    The copyright notice above does not evidence any       */
  297. X/*    actual or intended publication of such source code.    */
  298. X/*    So, use it if you like, but give me credit.        */
  299. X
  300. X
  301. X/*     Usage: plan [-f file_name] program_name            */
  302. X
  303. X
  304. X/*    Description:                    */
  305. X
  306. X/*     This program takes the full pathname of an    */
  307. X/*     executable and runs it on a fifo in the     */
  308. X/*    user's home directory named .plan.  This    */
  309. X/*     way, when finger is executed, the output    */
  310. X/*     of the program goes to the fifo.        */
  311. X    
  312. X/*    Written by:  Tony Rems                 */
  313. X
  314. X/*     Send bugs and flames to /dev/null or         */
  315. X/*     rembo@unisoft.com                 */
  316. X
  317. X/*    Modifications:                    */
  318. X
  319. X/*    September 1991                    */
  320. X/*           (by Geoff Loker geoff@mdms.moore.com)    */
  321. X/*    Modified the program so that the path to the    */
  322. X/*    .plan file is not hardcoded in.  Now any number    */
  323. X/*    of users can use the program at the same time.    */
  324. X/*    I also modified the program to use an optional    */
  325. X/*    argument to specify which file to use.  The    */
  326. X/*    default file used is still the user's .plan,    */
  327. X/*    but this can now also be used to set up        */
  328. X/*    .signatures or any other file the user wants.    */
  329. X
  330. X/*    Even more modifications                */
  331. X
  332. X/*    January 1992                    */
  333. X/*          (by Karen Bruner napalm@ugcs.caltech.edu) */
  334. X/*    Added pid_deal function, so people can stick    */
  335. X/*     the program in their .login, and then have it    */
  336. X/*    killed by their .logout.  Program will not    */
  337. X/*    run if a .planpid file, the file with the PID    */
  338. X/*    for plan, already exists in the user's home    */
  339. X/*    directory.                    */
  340. X
  341. X#include <sys/types.h>
  342. X#include <sys/file.h>
  343. X#include <stdio.h>
  344. X#include <fcntl.h>
  345. X#include <sys/stat.h>
  346. X#include <signal.h>
  347. X#include <string.h>
  348. X
  349. X/* Defines */
  350. X#define PERMS 0666
  351. X#define USAGE "%s [-f file_name] program_name\n"
  352. X
  353. X/* Function prototypes */
  354. Xvoid sig_handler();
  355. Xint pid_deal();    
  356. X
  357. Xmain (argc, argv)
  358. Xint argc;
  359. Xchar *argv[];
  360. X{
  361. X        int c, fflg;
  362. X    char *file;
  363. X        extern char *optarg;
  364. X    extern int optind;
  365. X    int fd;
  366. X    int pid;
  367. X    int status;
  368. X    char *getenv(), *home, plan[256], *strcat(), *strcpy();
  369. X    int pid_check;
  370. X    
  371. X    fflg = c = 0;
  372. X    while ((c = getopt(argc, argv, "f:")) != EOF) {
  373. X      file = optarg;
  374. X      fflg++;
  375. X    }
  376. X
  377. X/* Comment out the next line if you don't want to have PID recorded
  378. X   to file .planpid */
  379. X
  380. X    pid_check = pid_deal(); /* check for .planpid, if none, write
  381. X                   .planpid */
  382. X
  383. X/* Uncomment next line if you commented out previous line */
  384. X
  385. X/*  pid_check = 1; */
  386. X
  387. X  if (pid_check == 1)  /* execute remaining part of program if .planpid
  388. X              does not exist, i.e., no other plan process is
  389. X              running */
  390. X    {
  391. X    if (fflg)
  392. X      strcpy(plan, file);
  393. X    else {
  394. X      home = getenv("HOME");
  395. X      strcpy(plan, home);
  396. X      strcat(plan, "/.plan");
  397. X    }
  398. X/*    setenv("PLAN", plan, 1); */
  399. X
  400. X    if ( argc != optind + 1 ) {
  401. X        fprintf (stderr, USAGE, argv[0]);
  402. X        exit(1);
  403. X    }  /* if */
  404. X
  405. X/* Catch interrupts for cleanup */
  406. X    signal(SIGTERM, sig_handler);
  407. X    signal(SIGINT, sig_handler);
  408. X    signal(SIGHUP, sig_handler);
  409. X
  410. X    unlink (plan);
  411. X
  412. X/* Make the fifo */
  413. X    if ((mknod(plan, S_IFIFO | PERMS, 0)) < 0 ) {
  414. X        perror("mknod");
  415. X        exit(2);
  416. X    }  /* if */
  417. X
  418. X    while (1) {
  419. X        if ((fd = open(plan, O_WRONLY)) < 0 ) {
  420. X            perror("open");
  421. X            exit(3);
  422. X        } /* if */
  423. X
  424. X/* Once our open completes we know that someone else has
  425. X * opened the FIFO for reading, so we can know run our 
  426. X * program on it.  So, we fork, exec our program and
  427. X * wait for the child to complete.
  428. X */
  429. X        switch (pid = fork()) {
  430. X            case -1:
  431. X                perror("fork");
  432. X                exit(4);
  433. X                break;
  434. X            case 0:
  435. X/* If we're in the child, we copy our fifo to stdout */
  436. X/* and exec the program given */
  437. X                dup2(fd, 1);
  438. X                execlp(argv[optind],argv[optind],(void *)NULL);
  439. X                perror("child returned");
  440. X                exit(5);
  441. X                break;
  442. X            default:
  443. X/* If we're in the parent, we close the pipe and wait */
  444. X                close(fd);
  445. X                while (wait(&status) != pid)
  446. X                    ;
  447. X                break;
  448. X        } /* switch */
  449. X        sleep(2);
  450. X        close(fd);
  451. X    } /* while */
  452. X    }  /* end of my if (pid_check... */
  453. X
  454. X  else
  455. X    printf("plan already running\n");
  456. X
  457. X} /* main */
  458. X
  459. Xvoid sig_handler()  /* cleanup */
  460. X{
  461. X    char *plan, *getenv();
  462. X    
  463. X    plan = getenv("PLAN");
  464. X
  465. X    unlink(plan);
  466. X    exit(0);
  467. X}
  468. X
  469. Xint pid_deal()    /* function for recording pid and making sure process
  470. X           isn't already running */
  471. X{
  472. X  char savepid[100];    /* string for file name */
  473. X  FILE *sp;
  474. X  int checker;        /* return value:  0 if .planpid exists, and
  475. X               program shouldn't be run, 1 if not */
  476. X  char *home;
  477. X
  478. X  home = getenv("HOME");        /* put save name for file */
  479. X  strcpy(savepid, home);        /* in savepid */
  480. X  strcat(savepid, "/.planpid");
  481. X
  482. X  if ((sp = fopen(savepid, "r")) != NULL) /* test for existence of 
  483. X                         .planpid by trying to open
  484. X                         the file for reading */
  485. X    checker = 0;     /* return a zero if read was successful, i.e.,
  486. X               file already exists */
  487. X    
  488. X  else
  489. X    checker = 1;    /* file doesn't exist, return a 1 to execute
  490. X               the rest of the program */
  491. X  fclose(sp);
  492. X
  493. X  if (checker == 1)
  494. X    {
  495. X      sp = fopen(savepid, "w");
  496. X      fprintf(sp, "%d", getpid());     /* puts PID for plan into file */
  497. X      fclose(sp);
  498. X    }
  499. X
  500. X  return checker;
  501. X} 
  502. END_OF_FILE
  503.   if test 5034 -ne `wc -c <'plan.c'`; then
  504.     echo shar: \"'plan.c'\" unpacked with wrong size!
  505.   fi
  506.   # end of 'plan.c'
  507. fi
  508. if test -f 'plan.header' -a "${1}" != "-c" ; then 
  509.   echo shar: Will not clobber existing file \"'plan.header'\"
  510. else
  511.   echo shar: Extracting \"'plan.header'\" \(731 characters\)
  512.   sed "s/^X//" >'plan.header' <<'END_OF_FILE'
  513. XThe following is the best implementation of a named pipe I have yet
  514. Xfound. It can be used for generating a random .plan, .signature, 
  515. Xetc. It has been modified and improved upon by a number of authors, 
  516. Xand I have seen fit to repackage it with a simplistic means of
  517. Xinstallation, and a cool trick or two. I hope that people will use
  518. Xit wisely, because it can mess up machines (read docs) if you use it
  519. Ximproperly. 
  520. X
  521. X   Direct questions to franklin@ug.cs.dal.ca
  522. X   Hope you find it interesting...
  523. X
  524. XSteve
  525. X
  526. Xp.s. of course, it's a uuencoded and zipped file. Perhaps as part of
  527. Xyour test to deem your worthiness, I have used the latest version of
  528. X"zip" to archive it. If you can't unzip this, you probably shouldn't
  529. Xbe installing it :)
  530. END_OF_FILE
  531.   if test 731 -ne `wc -c <'plan.header'`; then
  532.     echo shar: \"'plan.header'\" unpacked with wrong size!
  533.   fi
  534.   # end of 'plan.header'
  535. fi
  536. if test -f 'planner' -a "${1}" != "-c" ; then 
  537.   echo shar: Will not clobber existing file \"'planner'\"
  538. else
  539.   echo shar: Extracting \"'planner'\" \(877 characters\)
  540.   sed "s/^X//" >'planner' <<'END_OF_FILE'
  541. X#!/bin/sh
  542. Xperl $HOME/bin/namedp/logfinger
  543. X#  This previous line points to the logfinger script
  544. X
  545. XWHO=`netstat -n | head -20 | grep ESTABLISHED | grep 129.173.4.4.79 | head -1 | awk '{ p=NF-1;printf "%s\n",$p}' | awk -F. '{printf "%s.%s.%s.%s\n",$1,$2,$3,$4}'`
  546. X#                                                     ^^^^^^^^^^^^^
  547. X#                                  This is the finger port. Your IP number
  548. X#                                  plus .79 (the finger port suffix)
  549. X#                                  Change the IP number to reflect yours
  550. X
  551. Xif [ -z "$WHO" ]
  552. X   then WHO='129.173.4.4'
  553. Xfi
  554. X
  555. X#  If it doesn't catch any IP number fingering you then it must be a local
  556. X#  finger
  557. X
  558. XHOST=`host $WHO 2>/dev/null| grep Name | awk '{ printf "%s\n",$2 }'`
  559. Xecho "     " $WHO "->" $HOST >> $HOME/.fingerees
  560. Xecho "You're fingering me from "$WHO ", which is "$HOST
  561. XTIME=`date '+%H:%M, %D'`
  562. END_OF_FILE
  563.   if test 877 -ne `wc -c <'planner'`; then
  564.     echo shar: \"'planner'\" unpacked with wrong size!
  565.   fi
  566.   chmod +x 'planner'
  567.   # end of 'planner'
  568. fi
  569. if test -f 'readme.orig' -a "${1}" != "-c" ; then 
  570.   echo shar: Will not clobber existing file \"'readme.orig'\"
  571. else
  572.   echo shar: Extracting \"'readme.orig'\" \(5668 characters\)
  573.   sed "s/^X//" >'readme.orig' <<'END_OF_FILE'
  574. XAll I did was to put in a function that keeps track of the PID for
  575. Xplan by writing it to a file called ".planpid" in your home directory.
  576. XNow you run plan in your .login, and, to kill the process when you log
  577. Xout, put something like this in your .logout:
  578. X
  579. X    kill `cat /home/mine/.planpid`
  580. X    rm -f /home/mine/.planpid
  581. X
  582. XYou have to remove the .planpid (or modify the code), because the 
  583. Xprogram will not run if a plan is already running, which it assumes
  584. Xwhen it finds a .planpid file already there.
  585. X
  586. XIf someone wanted to run multiple plans, maybe one for a .signature
  587. Xand another for a .plan, the save name for the PID could be changed,
  588. Xand the program compiled twice (the binary is not that big, ~40K on
  589. Xthe HP 425's I used), or, if someone is really motivated, they could
  590. Xadd a command line argument for the save name.
  591. X
  592. XSure, my modification isn't very complex, but it does what I needed
  593. Xit to do, and maybe someone else can use it.
  594. X
  595. XKaren    (napalm@ugcs.caltech.edu)
  596. X
  597. X****  Additions by Geoff Loker ****
  598. X
  599. XI have modified Tony Rems' code for plan a bit to get rid of the
  600. Xnecessity for hard-coding in the file name to be set up as a FIFO.
  601. XThe program will now accept an optional argument that specifies the
  602. Xname of the FIFO to be used.  If that argument is not set, the default
  603. XFIFO is $HOME/.plan.
  604. X
  605. XIn order to use this program, your O/S needs to support named pipes.
  606. XYou also need to link in getopt for the changes to work.
  607. X
  608. XAny executable program can be set up to run when the specified FIFO is
  609. Xopened, but don't forget that the program you specify to run is being
  610. Xrun under your userid.
  611. X
  612. X****  Original README ****
  613. X
  614. XDate: Thu, 11 Apr 91 14:09:10 MST
  615. XFrom: Jim Armstrong <armstron@cs.arizona.edu>
  616. XSubject: RE: fingeree ...
  617. X
  618. X> >About a month ago there was a sample program posted to this newsgroup that
  619. X> >set up a FIFO named pipe as your .plan file.  I modified the code to set up
  620. X> >a simple (perhaps naive) finger monitor for users on my machine.  The process
  621. X> do you still have the source for it? would you send it to me?
  622. X
  623. XHere is the article which appeared in comp.unix.questions a while back.  It
  624. Xcontains generic code that will run any program you want whenever a certain
  625. Xfile is accessed (i.e. the .plan file in this case).  All you have to do is
  626. Xcompile it (it creates an executable called 'plan') and then to get it
  627. Xrunning say 'plan a.out &' where a.out is some program you have written.
  628. XI don't have my program any more, but basically what I did was a ps au
  629. Xwithin that program.  It used egrep to search for someone currently fingering
  630. Xme and appended the output to a file.  To get really fancy you could then
  631. Xread from that file to find out exactly who it is (all in the same program)
  632. Xand print out a nice personal message to whoever is fingering you as part
  633. Xof what looks to be your .plan file.  A couple of things to watch out for:
  634. XIf the finger is remote, the ps au won't find anything.  Also, if two people
  635. Xfinger you at the same time you may run into trouble, but I didn't try
  636. Xexperimenting with this too much.  I also found it helpful to timestamp a
  637. Xdate to the file, too (I used localtime() for efficiency).  This makes it
  638. Xeasier to look back later at the file and see who's been fingering you and
  639. Xwhen while you were not logged on.  It also helpful in debugging your program.
  640. X
  641. XSo set up this code and experiment with different programs.  Just be creative
  642. Xand see what else you can do with it.  One idea I used for a while is making
  643. Xit print a different quote each time.  The possibilites are endless.  Enjoy.
  644. X
  645. XJim
  646. X
  647. X
  648. XArticle 31270 of comp.unix.questions:
  649. XFrom: rembo@unisoft.UUCP (Tony Rems)
  650. XNewsgroups: comp.unix.questions
  651. XSubject: Re: Finger
  652. XDate: 22 Feb 91 02:44:17 GMT
  653. XReply-To: rembo@unisoft.UUCP (Tony Rems)
  654. XOrganization: UniSoft Corporation -- UNIX R Us.
  655. X
  656. XIn article <37675@netnews.upenn.edu> minzhi@eniac.seas.upenn.edu (Min-Zhi Shao) writes:
  657. X>
  658. X>    When I fingered our system administrator, I got the following result:
  659. X>
  660. X>_________________________________________________________________________
  661. X>Login name: gardella              In real life: Ed Gardella [CETS]
  662. X>Directory: /home/cets/gardella          Shell: /usr/local/bin/bash
  663. X>On since Feb 15 19:49:04 on ttyp1 from TSTEST.SEAS.UPEN
  664. X>14 minutes Idle Time
  665. X>No unread mail
  666. X>Project: System Administrator eniac.seas.upenn.edu
  667. X>Plan:
  668. X>         Meander about until something interesting comes along.
  669. X>
  670. X>Office: 154 Moore Building           Work Phone: 898-2491
  671. X>                                     Home Phone: 387-4104
  672. X>
  673. X>I have been fingered 3 times today
  674. X>_________________________________________________________________________
  675. X>
  676. X>the .plan file in his home directory looks like:
  677. X>
  678. X>prw-r--r--  1 gardella        0 Feb 15 23:48 /home/cets/gardella/.plan
  679. X>^
  680. X
  681. XAs you have found out by now, I'm sure, the p means that this is 
  682. Xa named pipe aka a FIFO.  If you'd like to do this yourself, here
  683. Xis a little program I wrote to do it (see the comments at the
  684. Xthe beginning of the plan.c file for usage info):  
  685. X
  686. XHere's the shar of my plan program, just cut up until it says
  687. X"cut here", and then type 'sh filename' using whatever filename
  688. Xyou save it as.  If you use 'plan' it will get overwritten.
  689. X
  690. XThe code here should compile w/o any problems on any BSD machine,
  691. XI have tried it on a Sun, Vax 750, and Pyramid 90x.  It should
  692. Xalso work properly on any SVR4.0 machine.  
  693. X
  694. XThe code is pretty heavily commented so it should be self
  695. Xexplanatory.  
  696. X
  697. XNote that you should put a -DFILENAME="your_home_dir/.plan"
  698. Xto get it to put your path in, or you can just edit the 
  699. Xsource and change the value of FILENAME permanently.  
  700. X
  701. XIf you have any problems getting it compiled, just send me mail.
  702. X
  703. XEnjoy.  
  704. X
  705. X-Tony
  706. X
  707. END_OF_FILE
  708.   if test 5668 -ne `wc -c <'readme.orig'`; then
  709.     echo shar: \"'readme.orig'\" unpacked with wrong size!
  710.   fi
  711.   # end of 'readme.orig'
  712. fi
  713. if test -f 'renewplan' -a "${1}" != "-c" ; then 
  714.   echo shar: Will not clobber existing file \"'renewplan'\"
  715. else
  716.   echo shar: Extracting \"'renewplan'\" \(357 characters\)
  717.   sed "s/^X//" >'renewplan' <<'END_OF_FILE'
  718. X#!/bin/sh
  719. X    if [ -f $HOME/.planpid ] ; then
  720. X        kill -9 `cat $HOME/.planpid` >/dev/null 2>&1 ;
  721. X        rm -f $HOME/.plan $HOME/.planpid >/dev/null 2>&1 ;
  722. X    fi
  723. X    if [ ! -f $HOME/.fingerees ] ; then
  724. X        echo " " >$HOME/.fingerees  ;
  725. X    fi;
  726. X    $HOME/bin/namedp/plan -f $HOME/.plan $HOME/bin/namedp/planner & sleep 2;
  727. X    chmod a+r $HOME/.plan
  728. X
  729. END_OF_FILE
  730.   if test 357 -ne `wc -c <'renewplan'`; then
  731.     echo shar: \"'renewplan'\" unpacked with wrong size!
  732.   fi
  733.   chmod +x 'renewplan'
  734.   # end of 'renewplan'
  735. fi
  736. echo shar: End of archive 1 \(of 1\).
  737. cp /dev/null ark1isdone
  738. MISSING=""
  739. for I in 1 ; do
  740.     if test ! -f ark${I}isdone ; then
  741.     MISSING="${MISSING} ${I}"
  742.     fi
  743. done
  744. if test "${MISSING}" = "" ; then
  745.     echo You have the archive.
  746.     rm -f ark[1-9]isdone
  747. else
  748.     echo You still must unpack the following archives:
  749.     echo "        " ${MISSING}
  750. fi
  751. exit 0
  752. exit 0 # Just in case...
  753.