2016-02-11 12:06:43 +03:00
#! /usr/bin/env perl
1996-05-04 11:50:46 +04:00
#
#@(#) smb-wall.pl Description:
#@(#) A perl script which allows you to announce whatever you choose to
#@(#) every PC client currently connected to a Samba Server...
#@(#) ...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.
1996-05-04 14:51:22 +04:00
#@(#) Hacked up by Keith Farrar <farrar@parc.xerox.com>
1996-05-04 11:50:46 +04:00
#
1996-05-04 14:51:22 +04:00
# 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.
1996-05-04 11:50:46 +04:00
#=============================================================================
1996-05-04 14:51:22 +04:00
$smbstatus = "/usr/local/bin/smbstatus";
$smbshout = "/usr/local/bin/smbclient -M";
1996-05-04 11:50:46 +04:00
1996-05-04 14:51:22 +04:00
if (@ARGV) {
@clients = @ARGV;
undef @ARGV;
1996-05-04 11:50:46 +04:00
}
1996-05-04 14:51:22 +04:00
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 (-t) {
print <<'EOT';
1996-05-04 11:50:46 +04:00
1996-05-04 14:51:22 +04:00
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 = <>;
1996-05-04 11:50:46 +04:00
}
1996-05-04 14:51:22 +04:00
foreach(@clients) {
## print "To $_:\n";
if (open(SENDMSG,"|$smbshout $_")) {
1996-05-04 11:50:46 +04:00
print SENDMSG @message;
close(SENDMSG);
1996-05-04 14:51:22 +04:00
}
else {
warn "Cannot notify $_ with $smbshout:\n$!\n";
}
1996-05-04 11:50:46 +04:00
}
1996-05-04 14:51:22 +04:00
exit 0;