[comp.unix.wizards] invoking write from cron

tomc@dftsrv.gsfc.nasa.gov (Tom Corsetti) (04/21/89)

Hi, 
I'm trying to set up a script that runs from cron, checks files
and sends me a message when certain files change in size.  I have
the following code in the script that sends the message:
        echo "message to send" | write userid
When I invoke the script interactively, it works.  When run from
cron, I get no message.  Is this because the write command also
sends userid and ttyxx device along with the message?  Since processes
invoked from cron have no tty associated with them, could this be the
problem?  Any suggestions are welcome!  Thanks in advance!
                                             - Tom

-- 
  Tom Corsetti                 * * * *   internet - tomc@dftsrv.gsfc.nasa.gov
  NASA/Goddard Space Flt Ctr    * * *    decnet   - dftnic::tomc
  Greenbelt Maryland           * * * *   bitnet   - tomc at dftbit

mjs@mentor.cc.purdue.edu (Mike Spitzer) (04/22/89)

In article <8594@xanth.cs.odu.edu> kremer@cs.odu.edu (Lloyd Kremer) writes:
>In article <175@dftsrv.gsfc.nasa.gov> tomc@dftsrv.gsfc.nasa.gov (Tom Corsetti)
>writes:
>
>>I'm trying to set up a script that runs from cron, checks files
>> ...
>>        echo "message to send" | write userid
>
>It works on our System V Release 3.  Write also issues a message to stderr
>reporting its inability to determine which terminal to use for replys, which
>cron mails to the crontab owner, but the message itself gets through OK.

Since Tom reported that it didn't work for him, I guess we can
assume that he not using System V Release 3.  4.3BSD write(1) exits
with a fatal error if it cannot find out what terminal the writer is
logged on to.  So, write isn't going to work under 4.3BSD if run from
inside cron.

It's relatively simple to write a shell script version of write using
echo, who, and awk that doesn't depend on a controlling tty.  You
might want to try that (or consider using logger(1)/syslog(8)
instead).

-- 
Michael J. Spitzer		Purdue University Computing Center
mjs@mentor.cc.purdue.edu	pur-ee!mentor.cc.purdue.edu!mjs

andrew@frip.wv.tek.com (Andrew Klossner) (04/25/89)

[]

	"4.3BSD write(1) exits with a fatal error if it cannot find out
	what terminal the writer is logged on to.  So, write isn't
	going to work under 4.3BSD if run from inside cron.  It's
	relatively simple to write a shell script version of write
	using echo, who, and awk that doesn't depend on a controlling
	tty."

It's even easier just to supply a controlling tty:

	echo "message to send" | write userid 2>/dev/console

  -=- Andrew Klossner   (uunet!tektronix!orca!frip!andrew)      [UUCP]
                        (andrew%frip.wv.tek.com@relay.cs.net)   [ARPA]

mhoffman@infocenter.UUCP (Mike Hoffman) (04/27/89)

in article <175@dftsrv.gsfc.nasa.gov>, tomc@dftsrv.gsfc.nasa.gov (Tom Corsetti) says:
> 
> I'm trying to set up a script that runs from cron, checks files
> and sends me a message when certain files change in size.  I have
> the following code in the script that sends the message:
>         echo "message to send" | write userid
> 

I've found the best solution to this (and many other similar tasks) is
Kenneth Ingham's "watcher" program. It runs from cron and uses a control
file to check on most anything you want it to, and compares the results
of its check to previous runs. It will send mail, so you can have "biff y"
and achieve the same results as "write userid".

Watcher should be available through your local comp.sources.misc archive
site. For general information, the author's address:

		Kenneth Ingham  <ingham@charon.unm.edu>
		University of New Mexico Computing Center
		2701 Campus NE
		Albuquerque, NM 87131

See also:

	"Keeping Watch over the Flocks by Night (and day), Kenneth Ingham,
		Summer 198 Usenix proceedings.

Hope this helps.
---------------------------------------------------------------------------
Michael J. Hoffman      {uunet,uflorida!novavax,sun,pur-ee}gould!mhoffman
Manufacturing Engineering                         
Encore Computer Corporation       
				"Curiouser and curiouser!" -Alice

friedl@vsi.COM (Stephen J. Friedl) (04/30/89)

In article <2134@infocenter.UUCP>, mhoffman@infocenter.UUCP (Mike Hoffman) writes:
> See also:
> 
> 	"Keeping Watch over the Flocks by Night (and day), Kenneth Ingham,
> 		Summer 198 Usenix proceedings.
                       ^^^

     Clearly Kenneth was ahead of his time :-)

     Steve
-- 
Stephen J. Friedl / V-Systems, Inc. / Santa Ana, CA / +1 714 545 6442 
3B2-kind-of-guy   / friedl@vsi.com  / {attmail, uunet, etc}!vsi!friedl

As long as Bush is in office, you'll never see Nancy Reagan in *my* .sig.

mhoffman@infocenter.UUCP (Mike Hoffman) (05/06/89)

in article <1111@vsi.COM>, friedl@vsi.COM (Stephen J. Friedl) says:
> 
> In article <2134@infocenter.UUCP>, mhoffman@infocenter.UUCP (Mike Hoffman) writes:
>> See also:
>> 
>> 	"Keeping Watch over the Flocks by Night (and day), Kenneth Ingham,
>> 		Summer 198 Usenix proceedings.
>                        ^^^

Oops... the sticky TV9220 keys strike again. Should be 1987  8-)

Mike