home *** CD-ROM | disk | FTP | other *** search
/ Source Code 1992 March / Source_Code_CD-ROM_Walnut_Creek_March_1992.iso / usenet / altsrcs / 1 / 1349 / wall
Encoding:
Text File  |  1990-12-28  |  1.1 KB  |  58 lines

  1. eval 'exec /bin/perl -wS $0 ${1+"$@"}'
  2.     if 0;
  3.  
  4. # $Id: wall,v 1.1 90/05/18 17:04:20 chip Exp $
  5. #
  6. # A Perl version of the "wall" command.
  7. # Created by Chip Salzenberg, 3 May 1990.
  8. # Changed per Usenet commentary, 18 May 1990.
  9. #
  10. # $Log:    wall,v $
  11. # Revision 1.1  90/05/18  17:04:20  chip
  12. # Initial revision
  13.  
  14. $| = 1;
  15.  
  16. ($me = getlogin) || (($me) = getpwuid($<));
  17. $me = "Somebody" unless $me;
  18.  
  19. print "Enter the message to broadcast.  End with ^D.\n" if -t STDIN;
  20. for (;;) {
  21.     print ">> " if -t STDIN;
  22.     $_ = <STDIN>;
  23.     unless (defined($_)) {
  24.         print "<EOF>\n" if -t STDIN;
  25.         last;
  26.     }
  27.     chop;
  28.     push(@MSG, "$_ \r\n");
  29. }
  30. unless (@MSG) {
  31.     print stderr "wall: no message.\n";
  32.     exit;
  33. }
  34. unshift(@MSG, "\007\r\nBroadcast Message from $me: \r\n");
  35.  
  36. open(WHO, "who|");
  37. while (<WHO>) {
  38.     chop;
  39.     ($user, $tty) = split;
  40.  
  41.     ## Skip ptys.
  42.     next if $tty =~ /^ttyp.$/;
  43.  
  44.     $TTY = "/dev/$tty";
  45.     unless (-c $TTY) {
  46.         print stderr "wall: $tty: no such device\n";
  47.         next;
  48.     }
  49.     unless (open(TTY, ">> $TTY")) {
  50.         print stderr "wall: can't write to $user on /dev/$tty: $!\n";
  51.         next;
  52.     }
  53.     print TTY @MSG;
  54.     close(TTY);
  55. }
  56. close(WHO);
  57.