Xref: utzoo alt.sources:1843 comp.unix.questions:21988 comp.lang.perl:1255 Path: utzoo!utgpu!news-server.csri.toronto.edu!clyde.concordia.ca!uunet!pdn!tscs!tct!chip From: chip@tct.uucp (Chip Salzenberg) Newsgroups: alt.sources,comp.unix.questions,comp.lang.perl Subject: A Perl version of "wall" Message-ID: <264186E0.17B3@tct.uucp> Date: 4 May 90 13:42:56 GMT Organization: ComDev/TCT, Sarasota, FL Lines: 93 [This article is a good example of why we need "comp.unix.admin".] Dismayed by the weird behavior of SCO Xenix "wall" (write to all users), I wrote a Perl version that I like a lot better: 1. It has nice prompts. 2. It tells you who you're writing to. 3. It skips pseudo-ttys, which is nice since we use pty-based multiscreens. (You may want to remove this feature.) Shar and enjoy. #! /bin/sh # This is a shell archive. Remove anything before this line, then unpack # it by saving it into a file and typing "sh file". To overwrite existing # files, type "sh file -c". You can also feed this as standard input via # unshar, or by typing "sh 'wall' <<'END_OF_FILE' Xeval 'exec /bin/perl -wS $0 ${1+"$@"}' X if 0; X X# X# A Perl version of the rather screwy Xenix "wall" command. X# Written by Chip Salzenberg, 3 May 1990. X# X X$| = 1; X X$_ = `who am i 2>/dev/null`; Xchop; X($me) = split; X$me = "Somebody" unless $me; X Xprint "Enter the message to broadcast. End with ^D.\n" if -t STDIN; Xfor (;;) { X print ">> "; X $_ = ; X unless (defined($_)) { X print "\n" if -t STDIN; X last; X } X chop; X push(@MSG, "$_ \r\n"); X} Xunless (@MSG) { X print stderr "wall: no message.\n"; X exit; X} Xunshift(@MSG, "\007\r\nBroadcast Message from $me: \r\n"); X Xopen(WHO, "who|"); Xwhile () { X chop; X @F = split; X $tty = $F[1]; X X next if $tty =~ /^ttyp.$/; X X $TTY = "/dev/$tty"; X unless (-c $TTY) { X print stderr "wall: $tty: no such device\n"; X next; X } X unless (open(TTY, ">> $TTY")) { X print stderr "wall: can't open /dev/$tty: $!\n"; X next; X } X print TTY @MSG; X close(TTY); X} Xclose(WHO); END_OF_FILE if test 911 -ne `wc -c <'wall'`; then echo shar: \"'wall'\" unpacked with wrong size! fi chmod +x 'wall' # end of 'wall' fi echo shar: End of shell archive. exit 0 -- Chip Salzenberg at ComDev/TCT ,