[comp.unix.programmer] how to put a program into .plan file

szeto@aludra.usc.edu (Johnny Szeto) (09/25/90)

Hi everyone:

	is there any way to put a shell script or a c-prog. into .plan
so that when someone fingers me it will be activated?

Truly
szeto

gmt@cs.arizona.edu (Gregg Townsend) (09/25/90)

In article <12175@chaph.usc.edu> szeto@aludra.usc.edu (Johnny Szeto) writes:

>  Is there any way to put a shell script or a c-prog. into .plan
>  so that when someone fingers me it will be activated?

I did this by making my .plan file a named pipe and driving it from a shell
script.  The script repeatedly executed a simple program and directed its
output to the .plan file.  Whenever finger (or cat or anything else) opened
the file, the program would execute once and print the time and temperature.
(The temperature was just an educated guess, but it fooled several people!)

    Gregg Townsend / Computer Science Dept / Univ of Arizona / Tucson, AZ 85721
    +1 602 621 4325     gmt@cs.arizona.edu     110 57 16 W / 32 13 45 N / +758m

hoppie@buengf.bu.edu (Tom Hopkins) (09/25/90)

On 24 Sep 90 22:47:18 GMT, szeto@aludra.usc.edu (Johnny Szeto) said:

> 	is there any way to put a shell script or a c-prog. into .plan
> so that when someone fingers me it will be activated?

Good Lord, I hope not!

Seriously, .plan is (as far as I know) a read-only sort of venture.  The
best you can do is make it interesting.  I have seen some interesting
creations done by the help of cursor controls, but that's about it.

-Tom Hopkins <hoppie@buengf.bu.edu>

subbarao@phoenix.Princeton.EDU (Kartik Subbarao) (09/26/90)

In article <30908@athertn.Atherton.COM> paul@Atherton.COM (Paul Sander) writes:

>Another interesting trick:  If the person doing the fingering has a terminal
>that can be programmed to echo a string (I understand some Tektronix terminals
>do this), you can have your .plan file program the terminal to issue a
>command to send mail.  Some people have actually done this, according to a
>reliable source :-)

Yeah - the "Reliable Source" I believe is UNIX System Security, by Kochan
and Wood. Certain intelligent terminals have "send" escape sequences, which
if typed or somehow echoed to the terminal, can execute any command.

				-Kartik



(I need a new .signature -- any suggestions?)
subbarao@{phoenix or gauguin}.Princeton.EDU -|Internet
kartik@silvertone.Princeton.EDU (NeXT mail)       -|	
subbarao@PUCC.BITNET			          - Bitnet

labb-4ac@web-4b.berkeley.edu (superMan (the web dweller)) (09/26/90)

In article <2782@idunno.Princeton.EDU> subbarao@phoenix.Princeton.EDU (Kartik Su
bbarao) writes:
>
>  [ some part deleted ]
>
>The "cool" way to do this is to set up your .plan as a named pipe with
>/etc/mknod.
>
>% /etc/mknod ~/.plan p (Assuming that any existing .plan is not there)
>
>Then you simply write a C program that checks the status of the file,
>to see whether someone (the fingerer) has opened it. Then simply
>write your message to the named pipe. You can do many fancy things with this.
>I know a user at our site who did something like this with his .plan, and every
>time you fingered him, it would say how many people had fingered him today,
>the weather, and even your name. And sometimes it would also finger the person
>who fingered in the first place.
>
>                               -Kartik

Pardon my ignorance, but how can you write a C program which checks the
status of the file to see whether someone has opened it?  Exactly what
system call or library function do you use?

Please send reply to Internet address achoi@cory.berkeley.edu.
Thank you so much for your reply.

Name:  Andrew Choi
Internet Address:  achoi@cory.berkeley.edu
#include <std/disclaimer.h>

cedman@lynx.ps.uci.edu (Carl Edman) (09/27/90)

In article <1990Sep26.155456.1656@agate.berkeley.edu> labb-4ac@web-4b.berkeley.edu (superMan (the web dweller)) writes:
   Pardon my ignorance, but how can you write a C program which checks the
   status of the file to see whether someone has opened it?  Exactly what
   system call or library function do you use?

   Please send reply to Internet address achoi@cory.berkeley.edu.
   Thank you so much for your reply.

   Name:  Andrew Choi
   Internet Address:  achoi@cory.berkeley.edu
   #include <std/disclaimer.h>

Here is the most simple possible solution. Something I tried a few
days ago. Run the output and try "cat tfifo". You will get 3 different
results then the run-ed program will terminate.

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

main()
   {
   int fd;
   unlink("tfifo");
   mkfifo("tfifo",S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP|S_IROTH|S_IWOTH);
   fd=open("tfifo",O_WRONLY);
   write(fd,"test1\n",7);
   close(fd);
   sleep(1);
   fd=open("tfifo",O_WRONLY);
   write(fd,"test2\n",7);
   close(fd);
   sleep(1);
   fd=open("tfifo",O_WRONLY);
   write(fd,"test3\n",7);
   close(fd);
   sleep(1);
   unlink("tfifo");
   }

I hope looking at this code will answer your question (Maybe your system
hasn't got mkfifo, use mknod then).













Theorectial Physicist,N.:A physicist whose   | Send mail
existence is postulated, to make the numbers |  to
balance but who is never actually observed   | cedman@golem.ps.uci.edu
in the laboratory.                           | edmanc@uciph0.ps.uci.edu

rwelch@diana.cair.du.edu (RANDY S WELCH) (09/27/90)

In article <1990Sep26.155456.1656@agate.berkeley.edu> labb-4ac@web-4b.berkeley.edu (superMan (the web dweller)) writes:


   Pardon my ignorance, but how can you write a C program which checks the
   status of the file to see whether someone has opened it?  Exactly what
   system call or library function do you use?


Somewhat along the same lines, how can one tell if a file you have been
reading has been mv'ed?  

-randy
-- 
Randy Welch   Mail to :  ...!ncar!scicom!bldr!randy or rwelch@du.edu
Boulder, CO   VOICE   :  303-442-6717
"Unfortunately, life contains an unavoidable element of unpredictability"
-David Lynch "The Angriest Dog in the World"

jsb@panix.UUCP (J. S. B'ach) (09/27/90)

In article <2782@idunno.Princeton.EDU> subbarao@phoenix.Princeton.EDU (Kartik Subbarao) writes:
)
)  [ some part deleted ]
)
)The "cool" way to do this is to set up your .plan as a named pipe with
)/etc/mknod.
)
)% /etc/mknod ~/.plan p (Assuming that any existing .plan is not there)
)
)Then you simply write a C program that checks the status of the file,
)to see whether someone (the fingerer) has opened it. Then simply
)write your message to the named pipe. You can do many fancy things with this.

And does this C program run all the time checking?  Or does it sleep
until fingered?  Even in the latter case some system resources are 
permanently tied up.  Now (as Emanuel Kant might say) if everyone were
to do this, the entire process table would fill up!
-- 
    jim (rutgers!cmcl2!panix!jsb,  uunet!jyacc!jsb, or apple!panix!jsb)

    "We have no art.  We sell everything for as much as we can get."

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

In article <1990Sep27.060223.29844@mercury.cair.du.edu> rwelch@diana.cair.du.edu (RANDY S WELCH) writes:
>Somewhat along the same lines, how can one tell if a file you have been
>reading has been mv'ed?  

Couldn't you just use access() to see if it's still in the same place?
If you think someone has mv'ed your file somewhere else and then mv'ed
another one in its place, I suppose you could stat the file and fstat
your descriptor and compare the two...

If Lafontaine's elk would spurn Tom Jones, the engine must be our head, the
dining car our esophagus, the guardsvan our left lung, the kettle truck our
shins, the first class compartment the piece of skin at the nape of the neck,
and the level crossing an electric elk called Simon.

dylan@ibmpcug.co.uk (Matthew Farwell) (09/29/90)

In article <10511@panix.UUCP> jsb@panix.UUCP (J. S. B'ach) writes:
>In article <2782@idunno.Princeton.EDU> subbarao@phoenix.Princeton.EDU (Kartik Subbarao) writes:
>)Then you simply write a C program that checks the status of the file,
>)to see whether someone (the fingerer) has opened it. Then simply
>)write your message to the named pipe. You can do many fancy things with this.
>
>And does this C program run all the time checking?  Or does it sleep
>until fingered?  Even in the latter case some system resources are 
>permanently tied up.  Now (as Emanuel Kant might say) if everyone were
>to do this, the entire process table would fill up!

No. If you write on a pipe with noone at the other end, then the process
blocks (doesn't do anything), until someone starts reading from the pipe.
I had a similar version to r$'s running on this machine for about 8 hours
and it consumed 0.00 cpu seconds (according to ps). The process only takes
up cpu if someone fingers you.

Dylan.
-- 
Matthew J Farwell                 | Email: dylan@ibmpcug.co.uk
The IBM PC User Group, PO Box 360,|        ...!uunet!ukc!ibmpcug!dylan
Harrow HA1 4LQ England            | CONNECT - Usenet Access in the UK!!
Phone: +44 81-863-1191            | Sun? Don't they make coffee machines?

pfalstad@burn.Princeton.EDU (Paul John Falstad) (09/29/90)

In article <10511@panix.UUCP> jsb@panix.UUCP (J. S. B'ach) writes:
>In article <2782@idunno.Princeton.EDU> subbarao@phoenix.Princeton.EDU (Kartik Subbarao) writes:
>)The "cool" way to do this is to set up your .plan as a named pipe with
>)/etc/mknod.
>)Then you simply write a C program that checks the status of the file,
>)to see whether someone (the fingerer) has opened it. Then simply
>)write your message to the named pipe. You can do many fancy things with this.
>And does this C program run all the time checking?
No.
																  Or does it sleep
>until fingered?

Yes.  It blocks until the file is opened.

					  Even in the latter case some system resources are 
>permanently tied up.  Now (as Emanuel Kant might say) if everyone were
>to do this, the entire process table would fill up!

True.  I wouldn't do this, but it is a neat hack.  This would take up
a lot of swap space and process table space.  Perhaps you could run it
just when you're logged on, and replace the named pipe with a
conventional .plan in your .logout.

Then again, someone at our site used to have a planserver that
would create a new .plan file every 5 seconds, inserting a new funny
quote each time.  This solution with the named pipes is DEFINITELY
preferable to that one, I'm sure you'll agree.

On this same subject:

In some article somewhere, Dan Bernstein writes:
>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. :-)

Oh, well, of course.  I was just demonstrating the principle.  If I had
a planserver, I'd probably make it a C program.  I was just showing that
a planserver does not have to be some complicated program with select(2)
and all that.  Some error checking and the extra features could have been
added to my shell script as well.  The wasted execs are a problem,
as they would be with any shell script.

Write code for Berkeley....  Hmmm....

--
Here is the address to complain to:
pfalstad@phoenix.princeton.edu PLink:HYPNOS GEnie:P.FALSTAD CIS: 70016,1355
That address again,
sync@thumper.princeton.edu PLink:OHS738 GEnie:OHS738 CIS: 4128 143 1234 937

ericco@sag4.ssl.berkeley.edu (Eric C. Olson) (10/02/90)

In article <8715@pitt.UUCP> berson@speedy.cs.pitt.edu.UUCP (David A. Berson) writes:
>In article <E-267M3@xds13.ferranti.com> peter@ficc.ferranti.com (Peter da Silva) writes:
>>For even more fun... put your program into a file with a name like "resume"
>>or "private.mbox" and catch the snoops on your system.
>However if I were going to snoop I would probably do a
>ls -l before I tried to read anything.

An even better snoop catcher is to put an executable 'ls' in your directory.

:-> Eric

Eric
ericco@ssl.berkeley.edu

6sigma2@polari.UUCP (Brian Matthews) (10/03/90)

In article <1990Oct2.031551.11562@agate.berkeley.edu> ericco@sag4.ssl.berkeley.edu (Eric C. Olson) writes:
|In article <8715@pitt.UUCP> berson@speedy.cs.pitt.edu.UUCP (David A. Berson) writes:
|>In article <E-267M3@xds13.ferranti.com> peter@ficc.ferranti.com (Peter da Silva) writes:
|>>For even more fun... put your program into a file with a name like "resume"
|>>or "private.mbox" and catch the snoops on your system.
|>However if I were going to snoop I would probably do a
|>ls -l before I tried to read anything.
|An even better snoop catcher is to put an executable 'ls' in your directory.

No UNIX hacker who deserves the name has . or an empty field in their
path.
-- 
Brian L. Matthews	blm@6sceng.UUCP

lbr@holos0.uucp (Len Reed) (10/03/90)

In article <1990Oct2.031551.11562@agate.berkeley.edu> ericco@sag4.ssl.berkeley.edu (Eric C. Olson) writes:
>In article <8715@pitt.UUCP> berson@speedy.cs.pitt.edu.UUCP (David A. Berson) writes:
>An even better snoop catcher is to put an executable 'ls' in your directory.

Well, that would only catch snoops who have "." at the head of their $PATH;
informed users don't set up their paths that way because it's an invitation
to Trojan horses.  Like yours.

-- 
Len Reed
Holos Software, Inc.
Voice: (404) 496-1358
UUCP: ...!gatech!holos0!lbr

rbj@uunet.UU.NET (Root Boy Jim Cottrell) (10/04/90)

In article <2534@polari.UUCP> 6sigma2@polari.UUCP (Brian Matthews) writes:
>|An even better snoop catcher is to put an executable 'ls' in your directory.
>
>No UNIX hacker who deserves the name has . or an empty field in their
>path.
>-- 
>Brian L. Matthews	blm@6sceng.UUCP

I just checked mimsy. Chris Torek has `.' last in his path.

On our machine, the following people have `.' first:

	Rick Adams
	Brandon Allbery
	Robert Elz (kre)
	Dan Heller (argv)

The following people have `.' last:

	Rich Salz (rsalz)
	Eric Allman
	John Quarterman (jsq)
	Peter Honeyman
	Kirk McKusick
	Guy Harris

I put `.' first as well as most of the other staff here. I suppose
the reason is that, in keeping with the original UNIX philosophy,
we value convenience over security. Those who are slighty more
cautious (esp if they live on university machines :-) put `.' last.

I suppose we could all live without `.' in our path easily enuf.
Perhaps it is habit and optimism that keep it there.

-- 
	Root Boy Jim Cottrell
	<rbj@uunet.uu.net>

brnstnd@kramden.acf.nyu.edu (Dan Bernstein) (10/04/90)

In article <107255@uunet.UU.NET> rbj@uunet.UU.NET (Root Boy Jim Cottrell) writes:
> I suppose we could all live without `.' in our path easily enuf.
> Perhaps it is habit and optimism that keep it there.

Yep, I think so. I spent a couple of months training myself away from a
path with . into a path without, and I've never regretted the change:
it's perfectly natural to me now to execute programs with ./ if they're
in the current directory. I still have a dotpath alias (and its inverse,
nodotpath) to deal with those annoying shell scripts that depend on . in
the path; I rarely use it.

---Dan

lwall@jpl-devvax.JPL.NASA.GOV (Larry Wall) (10/05/90)

In article <29485:Oct404:23:4390@kramden.acf.nyu.edu> brnstnd@kramden.acf.nyu.edu (Dan Bernstein) writes:
: In article <107255@uunet.UU.NET> rbj@uunet.UU.NET (Root Boy Jim Cottrell) writes:
: > I suppose we could all live without `.' in our path easily enuf.
: > Perhaps it is habit and optimism that keep it there.
: 
: Yep, I think so. I spent a couple of months training myself away from a
: path with . into a path without, and I've never regretted the change:
: it's perfectly natural to me now to execute programs with ./ if they're
: in the current directory. I still have a dotpath alias (and its inverse,
: nodotpath) to deal with those annoying shell scripts that depend on . in
: the path; I rarely use it.

I often execute programs with "./" too, but for an entirely different reason.
Seems my history character is a comma.  So I'm in the habit of rerunning
the program I'm testing by saying ",.", which is very fast to type.

I work very hard at being as lazy as possible.

However, I see no difficulty at all with leaving . on the end of my path.
I believe it will save me more grief than it will cause me over the long
run.

And I work very hard at being as lazy as possible.

Larry Wall
lwall@jpl-devvax.jpl.nasa.gov