invoking write from cron $W could not be reached

Bob Peirce news at investor.UUCP
Thu Apr 27 23:37:11 AEST 1989


In article <2505 at mentor.cc.purdue.edu> mjs at mentor.cc.purdue.edu (Mike Spitzer) writes:
>In article <8594 at xanth.cs.odu.edu> kremer at cs.odu.edu (Lloyd Kremer) writes:
>>In article <175 at dftsrv.gsfc.nasa.gov> tomc at 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).

It doesn't work on our Sys V Rel 2 either.  If the write command isn't
generated from a terminal it dies.  We get around it by determining the
terminal the target user is logged into and catting directly to that
device.  If there is no write permission on the device we send mail.

#--------------------------  CUT HERE  ------------------------------
# -- xmt:  Attempt to get around write restriction in at/cron

PATH=:/usr/local/bin:/usr/local/sh:/bin:/usr/bin
export PATH

if [ $# -ne 2 ]
then
	echo 'usage:  xmt login "message"'
	exit 1
fi
W=$1
M=$2

#  Trap possible garbage if "to" is not logged in
set `who | grep $1 || echo XXX Unknown`
TO=$1
TTY=$2

U=$LOGNAME

if [ $TO = "XXX"  -o ! -w /dev/$TTY ]
then
	mail $U <<~
Subject: $W could not be reached
Message: $M
~
else
	cat >> /dev/$TTY <<~





		<insert ^G here>Mesasage from $U ...

$M





~
fi


-- 
Bob Peirce, Pittsburgh, PA				 412-471-5320
uucp: ...!{allegra, bellcore, cadre, idis, psuvax1}!pitt!investor!rbp
	    NOTE:  Mail must be < 30K  bytes/message



More information about the Comp.unix.wizards mailing list