home *** CD-ROM | disk | FTP | other *** search
/ Source Code 1992 March / Source_Code_CD-ROM_Walnut_Creek_March_1992.iso / usenet / altsrcs / 1 / 1273 / wall
Encoding:
Text File  |  1990-12-28  |  911 b   |  54 lines

  1. eval 'exec /bin/perl -wS $0 ${1+"$@"}'
  2.     if 0;
  3.  
  4. #
  5. # A Perl version of the rather screwy Xenix "wall" command.
  6. # Written by Chip Salzenberg, 3 May 1990.
  7. #
  8.  
  9. $| = 1;
  10.  
  11. $_ = `who am i 2>/dev/null`;
  12. chop;
  13. ($me) = split;
  14. $me = "Somebody" unless $me;
  15.  
  16. print "Enter the message to broadcast.  End with ^D.\n" if -t STDIN;
  17. for (;;) {
  18.     print ">> ";
  19.     $_ = <STDIN>;
  20.     unless (defined($_)) {
  21.         print "<EOF>\n" if -t STDIN;
  22.         last;
  23.     }
  24.     chop;
  25.     push(@MSG, "$_ \r\n");
  26. }
  27. unless (@MSG) {
  28.     print stderr "wall: no message.\n";
  29.     exit;
  30. }
  31. unshift(@MSG, "\007\r\nBroadcast Message from $me: \r\n");
  32.  
  33. open(WHO, "who|");
  34. while (<WHO>) {
  35.     chop;
  36.     @F = split;
  37.     $tty = $F[1];
  38.  
  39.     next if $tty =~ /^ttyp.$/;
  40.  
  41.     $TTY = "/dev/$tty";
  42.     unless (-c $TTY) {
  43.         print stderr "wall: $tty: no such device\n";
  44.         next;
  45.     }
  46.     unless (open(TTY, ">> $TTY")) {
  47.         print stderr "wall: can't open /dev/$tty: $!\n";
  48.         next;
  49.     }
  50.     print TTY @MSG;
  51.     close(TTY);
  52. }
  53. close(WHO);
  54.