home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 October / usenetsourcesnewsgroupsinfomagicoctober1994disk2.iso / unix / volume3 / hey < prev    next >
Text File  |  1986-11-30  |  7KB  |  260 lines

  1. Subject: Hey(1) [from Unix/World, Oct. 85]
  2. From: Bob Desinger <genrad!decvax!ucbvax!hpda!bd>
  3. Newsgroups: mod.sources
  4. Approved: jpn@panda.UUCP
  5.  
  6. Mod.sources:  Volume 3, Issue 10
  7. Submitted by: Bob Desinger <decvax!ucbvax!hpda!bd>
  8.  
  9.  
  10. The hey(1) program, published in the October 1985 Unix/World's magazine's
  11. Wizard Grabbag column, attempts to contact a particular person by writing to
  12. all terminals that s/he is using.  To save the net some typing, here's a
  13. (slightly improved) machine-readable copy.
  14.  
  15. The version packed as "hey" in this bundle is a superset of the one published
  16. in the magazine.  The new one handles a -n option to look you up all over the
  17. (4.2BSD-style) network.  The published magazine version looks only on the local
  18. system, and is packed here as "hey.local".  The enclosed man page documents the
  19. networked version.
  20.  
  21. I haven't seen the issue yet, but I received mail asking for the networked copy
  22. so I guess it's been published.  I recently updated the man page with better
  23. English, so this copy is more up-to-date.  I don't know if there have been any
  24. bugs introduced by the publishing process (copy is frequently mangled in its
  25. travel from the submittal to the final page), so trust this version.
  26.  
  27. -- Bob Desinger        ucbvax!hpda!bd        hpda!bd@BERKELEY
  28.  
  29. PS:    I'm hoping to start a trend here.  If you send sources to a magazine,
  30.     please send duplicates to mod.sources when they're published (if the
  31.     magazine's editors don't mind).
  32.  
  33.  
  34. # This is a shell archive.  Remove anything before this line,
  35. # then unpack it by saving it in a file and typing "sh file".
  36. #
  37. # Wrapped by hpda!bd on Thu Sep  5 17:37:58 PDT 1985
  38. # Contents:  hey.1 hey hey.local
  39.  
  40. echo x - hey.1
  41. sed 's/^@//' > "hey.1" <<'@//E*O*F hey.1//'
  42. @.TH HEY LOCAL Public-Domain
  43. @.ad b
  44. @.SH NAME
  45. hey \- write to all terminals that a person is using
  46. @.SH SYNOPSIS
  47. \fBhey\fR [\fB-n\fR] person message
  48. @.SH DESCRIPTION
  49. @.I Hey
  50. writes a
  51. @.I message
  52. to all terminals being used by the login
  53. @.IR person .
  54. The
  55. @.I message
  56. is broadcast via
  57. @.IR write (1),
  58. which prints an initial banner identifying the sender.
  59. If the
  60. @.I person
  61. isn't logged in, the
  62. @.I message
  63. is mailed.
  64. @.PP
  65. The
  66. @.B \-n
  67. option causes
  68. @.I hey
  69. to track the person down across the local network.
  70. By default,
  71. @.I hey
  72. looks for the
  73. @.IR person 's
  74. logins only on the local system.
  75. @.PP
  76. Permission to write to a terminal is granted or denied by the
  77. @.IR mesg (1)
  78. command.
  79. @.SH EXAMPLES
  80. Assuming your own login is
  81. @.B me
  82. and the other person's login is
  83. @.BR you :
  84. @.sp
  85. @.RS
  86. (incredibly-long-running-command; hey me all done) &
  87. @.br
  88. hey you Call your wife at home, she just called.
  89. @.br
  90. hey root the console is out of paper
  91. @.RE
  92. @.PP
  93. Note that multi-line messages can be sent via newlines within quotes (from
  94. @.IR /bin/sh )
  95. as in:
  96. @.sp
  97. @.RS
  98. @.nf
  99. hey you 'This
  100. is spread
  101. across
  102. a few lines.'
  103. @.fi
  104. @.sp
  105. @.RE
  106. The same effect is possible from
  107. @.I csh
  108. by typing a backslash (escaped newline) at the end of the message lines.
  109. @.SH DIAGNOSTICS
  110. \fIYou have write permission turned off\fR as printed by
  111. @.IR write (1).
  112. @.SH "SEE ALSO"
  113. mesg(1),
  114. talk(1),
  115. wall(1),
  116. write(1)
  117. @.SH BUGS
  118. Denying write-access via
  119. @.I mesg
  120. works only with local messages.
  121. The
  122. @.B \-n
  123. option handcrafts a faked
  124. @.I write
  125. via
  126. @.IR rsh (1)
  127. and
  128. @.IR cat (1),
  129. which seems to be able to break through steel.
  130. @.PP
  131. This command makes it easy for some people to be obnoxious.
  132. @//E*O*F hey.1//
  133. chmod u=rw,g=r,o=r hey.1
  134.  
  135. echo x - hey
  136. sed 's/^@//' > "hey" <<'@//E*O*F hey//'
  137. : Broadcast a message to all ttys that a person is logged into.
  138.  
  139. # System-dependent commands (customize for your installation):
  140. GETHOST='hostname'    # some systems use 'uuname -l'
  141. MAILER='Mail'        # some systems use 'mailx'
  142. WHOIAM='$USER'        # some systems use '$LOGNAME'
  143. cmd=`basename $0`    # makes diagnostics under csh look better
  144. USAGE="Usage:  $cmd [-n] login  Your message here"
  145.  
  146. # Are we local-only or networked?
  147. case "$1" in
  148. -n)    networked=TRUE; shift;;
  149. -*)    echo 1>&2 "$USAGE"; exit 1;;    # trap bad options
  150. esac
  151.  
  152. # If we have enough args, find out who to talk at.
  153. if [ $# -lt 2 ]
  154. then    echo 1>&2 "$USAGE"; exit 1
  155. else    you=$1; shift
  156. fi
  157.  
  158. # Send the message to each terminal the specified person is logged into.
  159. # If the person isn't logged in anywhere, mail the message to them.
  160. if [ -z "$networked" ]
  161.  
  162. then    # not networked (local delivery only) -- speedy version
  163.     ttys=`who | sed -n '/^'$you' /s/^'$you'  *\(tty[^ ]*\) .*/\1/p'`
  164.     if [ -z "$ttys" ]
  165.     then    # not logged in
  166.         echo 1>&2 "$cmd: $you not logged in;" \
  167.             "sending your message via mail."
  168.         echo "$@" | $MAILER -s "Hey, $you!" $you
  169.     else    # logged in one or more times
  170.         for tty in $ttys
  171.         do
  172.             echo "Hey, $you:  $@" | write $you $tty
  173.         done
  174.     fi
  175.  
  176. else    # networked
  177.     me=`eval echo $WHOIAM`
  178.     myhost=`$GETHOST`
  179.     mytty="on `basename \`tty\``"
  180.     if [ "$mytty" = "on not" ]    # "not a tty" from LAN or crontab
  181.     then mytty="in hyperspace"
  182.     fi
  183.     today=`date`
  184.  
  185.     rwho -a |
  186.     sed -n '/^'$you' /s/^'$you' *\([^: ]*\):\(tty[^ ]*\) .*/\1 \2/p' |
  187.     while read system tty
  188.     do
  189.         cat >>/tmp/hey$$ <<@@@
  190. rsh $system -n 'cat >/dev/$tty <<\!
  191. Message from $myhost!$me $mytty at $today ...
  192. Hey, $you:  $@
  193. EOF
  194. !
  195. '
  196. @@@@
  197.     done
  198.     if [ -s /tmp/hey$$ ]    # logged in anywhere?
  199.     then    sh /tmp/hey$$    # yup
  200.     else    echo 1>&2 "$cmd: $you not logged in;" \
  201.             "sending your message via mail."
  202.         echo "$@" | $MAILER -s "Hey, $you!" $you
  203.     fi
  204.     rm -f /tmp/hey$$
  205. fi
  206. @//E*O*F hey//
  207. chmod u=rwx,g=rx,o=rx hey
  208.  
  209. echo x - hey.local
  210. sed 's/^@//' > "hey.local" <<'@//E*O*F hey.local//'
  211. : Broadcast a message to all ttys that a person is logged into.
  212.  
  213. # System-dependent command (customize for your installation):
  214. MAILER='Mail'        # some systems use 'mailx'
  215.  
  216. cmd=`basename $0`    # makes diagnostics under csh look better
  217. USAGE="Usage:  $cmd login  Your message here"
  218.  
  219. # If we have enough args, find out who to talk at.
  220. if [ $# -lt 2 ]
  221. then    echo 1>&2 "$USAGE"; exit 1
  222. else    you=$1; shift
  223. fi
  224.  
  225. # Send the message to each terminal the specified person is logged into.
  226. # If the person isn't logged in anywhere, mail the message to them.
  227. # This version is non-networked (for local delivery only).
  228.  
  229. ttys=`who | sed -n '/^'$you' /s/^'$you'  *\(tty[^ ]*\) .*/\1/p'`
  230. if [ -z "$ttys" ]
  231. then    # not logged in
  232.     echo 1>&2 "$cmd: $you not logged in;" \
  233.         "sending your message via mail."
  234.     echo "$@" | $MAILER -s "Hey, $you!" $you
  235. else    # logged in one or more times
  236.     for tty in $ttys
  237.     do
  238.         echo "Hey, $you:  $@" | write $you $tty
  239.     done
  240. fi
  241. @//E*O*F hey.local//
  242. chmod u=rwx,g=rx,o=rx hey.local
  243.  
  244. echo Inspecting for damage in transit...
  245. temp=/tmp/shar$$; dtemp=/tmp/.shar$$
  246. trap "rm -f $temp $dtemp; exit" 0 1 2 3 15
  247. cat > $temp <<\!!!
  248.       90     295    1591 hey.1
  249.       69     323    1868 hey
  250.       30     167     930 hey.local
  251.      189     785    4389 total
  252. !!!
  253. wc  hey.1 hey hey.local | sed 's=[^ ]*/==' | diff -b $temp - >$dtemp
  254. if [ -s $dtemp ]
  255. then echo "Ouch [diff of wc output]:" ; cat $dtemp
  256. else echo "No problems found."
  257. fi
  258. exit 0
  259.  
  260.