From 0e8fd3398771da2f016d72830179507f3edda51b Mon Sep 17 00:00:00 2001 From: Samba Release Account Date: Sat, 4 May 1996 07:50:46 +0000 Subject: Initial version imported to CVS (This used to be commit 291551d80711daab7b7581720bcd9a08d6096517) --- examples/misc/wall.perl | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 examples/misc/wall.perl (limited to 'examples/misc/wall.perl') diff --git a/examples/misc/wall.perl b/examples/misc/wall.perl new file mode 100644 index 0000000000..fc3dc2e2c0 --- /dev/null +++ b/examples/misc/wall.perl @@ -0,0 +1,45 @@ +#!/usr/local/bin/perl +# +#@(#) 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. +#@(#) Hacked up by Keith Farrar +# +#============================================================================= +$smbstatus = "/usr/local/bin/smbstatus"; +$smbclient = "/usr/local/bin/smbclient"; + +print STDOUT "\nEnter message for Samba clients of this host\n"; +print STDOUT "(terminated with single '.' or end of file):\n"; + +while ( ) { + /^\.$/ && last; + push(@message, $_); +} + +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 ( ) { + /^[a-z]+[a-z0-9A-Z-_]+.+/ || next; + ($share, $user, $group, $pid, $client, @junk) = split; + $pcclient{$client} = $client; + } + close(PCLIST); +} + +foreach $pc ( keys(%pcclient) ) { + print STDOUT "Sending message "; + $debug && print STDOUT " <@message> \n"; + print STDOUT "To <$pc>\n"; + open(SENDMSG,"|$smbclient -M $pc") || next; + print SENDMSG @message; + close(SENDMSG); +} -- cgit From 5c909179e8fbf4c57c88b9699756578c4aa92e29 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Sat, 4 May 1996 10:51:22 +0000 Subject: updates to wall.perl from michal@ellpspace.math.ualberta.ca (This used to be commit 30909756b16b2c78769a976809046af0b6a98b6e) --- examples/misc/wall.perl | 76 ++++++++++++++++++++++++++++++++----------------- 1 file changed, 50 insertions(+), 26 deletions(-) (limited to 'examples/misc/wall.perl') diff --git a/examples/misc/wall.perl b/examples/misc/wall.perl index fc3dc2e2c0..9303658ce1 100644 --- a/examples/misc/wall.perl +++ b/examples/misc/wall.perl @@ -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 +#@(#) Hacked up by Keith Farrar # +# Cleanup and corrections by +# Michal Jaegermann +# 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"; -print STDOUT "\nEnter message for Samba clients of this host\n"; -print STDOUT "(terminated with single '.' or end of file):\n"; +$smbstatus = "/usr/local/bin/smbstatus"; +$smbshout = "/usr/local/bin/smbclient -M"; -while ( ) { - /^\.$/ && last; - push(@message, $_); +if (@ARGV) { + @clients = @ARGV; + undef @ARGV; } +else { # no clients specified explicitly + open(PCLIST, "$smbstatus |") || die "$smbstatus failed!.\n$!\n"; + while() { + 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'; -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 ( ) { - /^[a-z]+[a-z0-9A-Z-_]+.+/ || next; - ($share, $user, $group, $pid, $client, @junk) = split; - $pcclient{$client} = $client; - } - close(PCLIST); +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; + -- cgit