Sometimes we want to notify all clients that the system is going down (or whatever). wall isn't good enough because most of our users don't open terminals. The solution we found is based on zephyr. Attached is a script which scans /proc for users (utmp seems unreliable) and then sends a message to each.
-- A new cognitive theory of emotion, http://openheartlogic.org
#!/usr/bin/perl
use strict;
use warnings;
sub run {
my $cmd = join ' ', @_;
system(@_) == 0
or die "system $cmd failed: $?"
}
opendir my $dh, '/proc' or die "opendir $!";
while (defined (my $pid = readdir $dh)) {
next unless $pid =~ /^\d+$/;
my $cmdpath = "/proc/$pid/cmdline";
open(my $cmdline, $cmdpath) or die "open $!";
my $cmd = <$cmdline>;
next unless ($cmd and $cmd =~ /^zwgc\b/);
my @s = stat($cmdpath);
if ([EMAIL PROTECTED]) {
warn "can't stat $cmdpath";
next;
}
my $name = getpwuid($s[4]);
run 'zwrite', $name, '-m', @ARGV;
}
signature.asc
Description: Digital signature
