home *** CD-ROM | disk | FTP | other *** search
- eval 'exec /bin/perl -wS $0 ${1+"$@"}'
- if 0;
-
- # $Id: wall,v 1.1 90/05/18 17:04:20 chip Exp $
- #
- # A Perl version of the "wall" command.
- # Created by Chip Salzenberg, 3 May 1990.
- # Changed per Usenet commentary, 18 May 1990.
- #
- # $Log: wall,v $
- # Revision 1.1 90/05/18 17:04:20 chip
- # Initial revision
- #
-
- $| = 1;
-
- ($me = getlogin) || (($me) = getpwuid($<));
- $me = "Somebody" unless $me;
-
- print "Enter the message to broadcast. End with ^D.\n" if -t STDIN;
- for (;;) {
- print ">> " if -t STDIN;
- $_ = <STDIN>;
- unless (defined($_)) {
- print "<EOF>\n" if -t STDIN;
- last;
- }
- chop;
- push(@MSG, "$_ \r\n");
- }
- unless (@MSG) {
- print stderr "wall: no message.\n";
- exit;
- }
- unshift(@MSG, "\007\r\nBroadcast Message from $me: \r\n");
-
- open(WHO, "who|");
- while (<WHO>) {
- chop;
- ($user, $tty) = split;
-
- ## Skip ptys.
- next if $tty =~ /^ttyp.$/;
-
- $TTY = "/dev/$tty";
- unless (-c $TTY) {
- print stderr "wall: $tty: no such device\n";
- next;
- }
- unless (open(TTY, ">> $TTY")) {
- print stderr "wall: can't write to $user on /dev/$tty: $!\n";
- next;
- }
- print TTY @MSG;
- close(TTY);
- }
- close(WHO);
-