mirror of
https://github.com/samba-team/samba.git
synced 2024-12-22 13:34:15 +03:00
updates to wall.perl from michal@ellpspace.math.ualberta.ca
This commit is contained in:
parent
2cf4d958f4
commit
30909756b1
@ -6,40 +6,64 @@
|
||||
#@(#) ...using "smbclient -M" message to winpopup service.
|
||||
#@(#) Default usage is to message every connected PC.
|
||||
#@(#) Alternate usage is to message every pc on the argument list.
|
||||
#@(#) Hacked up by Keith Farrar <farrar@parc.xerox.com>
|
||||
#@(#) Hacked up by Keith Farrar <farrar@parc.xerox.com>
|
||||
#
|
||||
# Cleanup and corrections by
|
||||
# Michal Jaegermann <michal@ellpspace.math.ualberta.ca>
|
||||
# Message to send can be now also fed (quietly) from stdin; a pipe will do.
|
||||
#=============================================================================
|
||||
|
||||
$smbstatus = "/usr/local/bin/smbstatus";
|
||||
$smbclient = "/usr/local/bin/smbclient";
|
||||
$smbshout = "/usr/local/bin/smbclient -M";
|
||||
|
||||
print STDOUT "\nEnter message for Samba clients of this host\n";
|
||||
print STDOUT "(terminated with single '.' or end of file):\n";
|
||||
|
||||
while ( <STDIN> ) {
|
||||
/^\.$/ && last;
|
||||
push(@message, $_);
|
||||
if (@ARGV) {
|
||||
@clients = @ARGV;
|
||||
undef @ARGV;
|
||||
}
|
||||
else { # no clients specified explicitly
|
||||
open(PCLIST, "$smbstatus |") || die "$smbstatus failed!.\n$!\n";
|
||||
while(<PCLIST>) {
|
||||
last if /^Locked files:/;
|
||||
split(' ', $_, 6);
|
||||
# do not accept this line if less then six fields
|
||||
next unless $_[5];
|
||||
# if you have A LOT of clients you may speed things up by
|
||||
# checking pid - no need to look further if this pid was already
|
||||
# seen; left as an exercise :-)
|
||||
$client = $_[4];
|
||||
next unless $client =~ /^\w+\./; # expect 'dot' in a client name
|
||||
next if grep($_ eq $client, @clients); # we want this name once
|
||||
push(@clients, $client);
|
||||
}
|
||||
close(PCLIST);
|
||||
}
|
||||
|
||||
if ( $ARGV[0] ne "" ) {
|
||||
$debug && print STDOUT "Was given args: \n\t @ARGV\n";
|
||||
foreach $client ( @ARGV ) {
|
||||
$pcclient{$client} = $client;
|
||||
}
|
||||
} else {
|
||||
open( PCLIST, "$smbstatus | /bin/awk '/^[a-z]/ {print $5}' | /bin/sort | /bin/uniq|");
|
||||
while ( <PCLIST> ) {
|
||||
/^[a-z]+[a-z0-9A-Z-_]+.+/ || next;
|
||||
($share, $user, $group, $pid, $client, @junk) = split;
|
||||
$pcclient{$client} = $client;
|
||||
}
|
||||
close(PCLIST);
|
||||
if (-t) {
|
||||
print <<'EOT';
|
||||
|
||||
Enter message for Samba clients of this host
|
||||
(terminated with single '.' or end of file):
|
||||
EOT
|
||||
|
||||
while (<>) {
|
||||
last if /^\.$/;
|
||||
push(@message, $_);
|
||||
}
|
||||
}
|
||||
else { # keep quiet and read message from stdin
|
||||
@message = <>;
|
||||
}
|
||||
|
||||
foreach $pc ( keys(%pcclient) ) {
|
||||
print STDOUT "Sending message ";
|
||||
$debug && print STDOUT " <@message> \n";
|
||||
print STDOUT "To <$pc>\n";
|
||||
open(SENDMSG,"|$smbclient -M $pc") || next;
|
||||
foreach(@clients) {
|
||||
## print "To $_:\n";
|
||||
if (open(SENDMSG,"|$smbshout $_")) {
|
||||
print SENDMSG @message;
|
||||
close(SENDMSG);
|
||||
}
|
||||
else {
|
||||
warn "Cannot notify $_ with $smbshout:\n$!\n";
|
||||
}
|
||||
}
|
||||
|
||||
exit 0;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user