Relay-Version: version B 2.10.3 4.3bsd-beta 6/6/85; site seismo.CSS.GOV Posting-Version: version B 2.10.2 9/18/84; site brl-tgr.ARPA Path: seismo!brl-tgr!tgr!sources-request@panda.uucp From: sources-request@panda.uucp Newsgroups: net.sources Subject: Hey(1) [from Unix/World, Oct. 85] Message-ID: <1366@brl-tgr.ARPA> Date: 8 Sep 85 20:50:55 GMT Sender: news@brl-tgr.ARPA Lines: 253 Mod.sources: Volume 3, Issue 10 Submitted by: Bob Desinger The hey(1) program, published in the October 1985 Unix/World's magazine's Wizard Grabbag column, attempts to contact a particular person by writing to all terminals that s/he is using. To save the net some typing, here's a (slightly improved) machine-readable copy. The version packed as "hey" in this bundle is a superset of the one published in the magazine. The new one handles a -n option to look you up all over the (4.2BSD-style) network. The published magazine version looks only on the local system, and is packed here as "hey.local". The enclosed man page documents the networked version. I haven't seen the issue yet, but I received mail asking for the networked copy so I guess it's been published. I recently updated the man page with better English, so this copy is more up-to-date. I don't know if there have been any bugs introduced by the publishing process (copy is frequently mangled in its travel from the submittal to the final page), so trust this version. -- Bob Desinger ucbvax!hpda!bd hpda!bd@BERKELEY PS: I'm hoping to start a trend here. If you send sources to a magazine, please send duplicates to mod.sources when they're published (if the magazine's editors don't mind). # This is a shell archive. Remove anything before this line, # then unpack it by saving it in a file and typing "sh file". # # Wrapped by hpda!bd on Thu Sep 5 17:37:58 PDT 1985 # Contents: hey.1 hey hey.local echo x - hey.1 sed 's/^@//' > "hey.1" <<'@//E*O*F hey.1//' @.TH HEY LOCAL Public-Domain @.ad b @.SH NAME hey \- write to all terminals that a person is using @.SH SYNOPSIS \fBhey\fR [\fB-n\fR] person message @.SH DESCRIPTION @.I Hey writes a @.I message to all terminals being used by the login @.IR person . The @.I message is broadcast via @.IR write (1), which prints an initial banner identifying the sender. If the @.I person isn't logged in, the @.I message is mailed. @.PP The @.B \-n option causes @.I hey to track the person down across the local network. By default, @.I hey looks for the @.IR person 's logins only on the local system. @.PP Permission to write to a terminal is granted or denied by the @.IR mesg (1) command. @.SH EXAMPLES Assuming your own login is @.B me and the other person's login is @.BR you : @.sp @.RS (incredibly-long-running-command; hey me all done) & @.br hey you Call your wife at home, she just called. @.br hey root the console is out of paper @.RE @.PP Note that multi-line messages can be sent via newlines within quotes (from @.IR /bin/sh ) as in: @.sp @.RS @.nf hey you 'This is spread across a few lines.' @.fi @.sp @.RE The same effect is possible from @.I csh by typing a backslash (escaped newline) at the end of the message lines. @.SH DIAGNOSTICS \fIYou have write permission turned off\fR as printed by @.IR write (1). @.SH "SEE ALSO" mesg(1), talk(1), wall(1), write(1) @.SH BUGS Denying write-access via @.I mesg works only with local messages. The @.B \-n option handcrafts a faked @.I write via @.IR rsh (1) and @.IR cat (1), which seems to be able to break through steel. @.PP This command makes it easy for some people to be obnoxious. @//E*O*F hey.1// chmod u=rw,g=r,o=r hey.1 echo x - hey sed 's/^@//' > "hey" <<'@//E*O*F hey//' : Broadcast a message to all ttys that a person is logged into. # System-dependent commands (customize for your installation): GETHOST='hostname' # some systems use 'uuname -l' MAILER='Mail' # some systems use 'mailx' WHOIAM='$USER' # some systems use '$LOGNAME' cmd=`basename $0` # makes diagnostics under csh look better USAGE="Usage: $cmd [-n] login Your message here" # Are we local-only or networked? case "$1" in -n) networked=TRUE; shift;; -*) echo 1>&2 "$USAGE"; exit 1;; # trap bad options esac # If we have enough args, find out who to talk at. if [ $# -lt 2 ] then echo 1>&2 "$USAGE"; exit 1 else you=$1; shift fi # Send the message to each terminal the specified person is logged into. # If the person isn't logged in anywhere, mail the message to them. if [ -z "$networked" ] then # not networked (local delivery only) -- speedy version ttys=`who | sed -n '/^'$you' /s/^'$you' *\(tty[^ ]*\) .*/\1/p'` if [ -z "$ttys" ] then # not logged in echo 1>&2 "$cmd: $you not logged in;" \ "sending your message via mail." echo "$@" | $MAILER -s "Hey, $you!" $you else # logged in one or more times for tty in $ttys do echo "Hey, $you: $@" | write $you $tty done fi else # networked me=`eval echo $WHOIAM` myhost=`$GETHOST` mytty="on `basename \`tty\``" if [ "$mytty" = "on not" ] # "not a tty" from LAN or crontab then mytty="in hyperspace" fi today=`date` rwho -a | sed -n '/^'$you' /s/^'$you' *\([^: ]*\):\(tty[^ ]*\) .*/\1 \2/p' | while read system tty do cat >>/tmp/hey$$ <<@@@ rsh $system -n 'cat >/dev/$tty <<\! Message from $myhost!$me $mytty at $today ... Hey, $you: $@ EOF ! ' @@@@ done if [ -s /tmp/hey$$ ] # logged in anywhere? then sh /tmp/hey$$ # yup else echo 1>&2 "$cmd: $you not logged in;" \ "sending your message via mail." echo "$@" | $MAILER -s "Hey, $you!" $you fi rm -f /tmp/hey$$ fi @//E*O*F hey// chmod u=rwx,g=rx,o=rx hey echo x - hey.local sed 's/^@//' > "hey.local" <<'@//E*O*F hey.local//' : Broadcast a message to all ttys that a person is logged into. # System-dependent command (customize for your installation): MAILER='Mail' # some systems use 'mailx' cmd=`basename $0` # makes diagnostics under csh look better USAGE="Usage: $cmd login Your message here" # If we have enough args, find out who to talk at. if [ $# -lt 2 ] then echo 1>&2 "$USAGE"; exit 1 else you=$1; shift fi # Send the message to each terminal the specified person is logged into. # If the person isn't logged in anywhere, mail the message to them. # This version is non-networked (for local delivery only). ttys=`who | sed -n '/^'$you' /s/^'$you' *\(tty[^ ]*\) .*/\1/p'` if [ -z "$ttys" ] then # not logged in echo 1>&2 "$cmd: $you not logged in;" \ "sending your message via mail." echo "$@" | $MAILER -s "Hey, $you!" $you else # logged in one or more times for tty in $ttys do echo "Hey, $you: $@" | write $you $tty done fi @//E*O*F hey.local// chmod u=rwx,g=rx,o=rx hey.local echo Inspecting for damage in transit... temp=/tmp/shar$$; dtemp=/tmp/.shar$$ trap "rm -f $temp $dtemp; exit" 0 1 2 3 15 cat > $temp <<\!!! 90 295 1591 hey.1 69 323 1868 hey 30 167 930 hey.local 189 785 4389 total !!! wc hey.1 hey hey.local | sed 's=[^ ]*/==' | diff -b $temp - >$dtemp if [ -s $dtemp ] then echo "Ouch [diff of wc output]:" ; cat $dtemp else echo "No problems found." fi exit 0