param: fix FLAG_CMDLINE to be stored outside of the param table
[Samba.git] / examples / misc / wall.perl
blob9303658ce14ba06f2ed038fcd2e1ef63f4218f97
1 #!/usr/local/bin/perl
2 #
3 #@(#) smb-wall.pl Description:
4 #@(#) A perl script which allows you to announce whatever you choose to
5 #@(#) every PC client currently connected to a Samba Server...
6 #@(#) ...using "smbclient -M" message to winpopup service.
7 #@(#) Default usage is to message every connected PC.
8 #@(#) Alternate usage is to message every pc on the argument list.
9 #@(#) Hacked up by Keith Farrar <farrar@parc.xerox.com>
11 # Cleanup and corrections by
12 # Michal Jaegermann <michal@ellpspace.math.ualberta.ca>
13 # Message to send can be now also fed (quietly) from stdin; a pipe will do.
14 #=============================================================================
16 $smbstatus = "/usr/local/bin/smbstatus";
17 $smbshout = "/usr/local/bin/smbclient -M";
19 if (@ARGV) {
20 @clients = @ARGV;
21 undef @ARGV;
23 else { # no clients specified explicitly
24 open(PCLIST, "$smbstatus |") || die "$smbstatus failed!.\n$!\n";
25 while(<PCLIST>) {
26 last if /^Locked files:/;
27 split(' ', $_, 6);
28 # do not accept this line if less then six fields
29 next unless $_[5];
30 # if you have A LOT of clients you may speed things up by
31 # checking pid - no need to look further if this pid was already
32 # seen; left as an exercise :-)
33 $client = $_[4];
34 next unless $client =~ /^\w+\./; # expect 'dot' in a client name
35 next if grep($_ eq $client, @clients); # we want this name once
36 push(@clients, $client);
38 close(PCLIST);
41 if (-t) {
42 print <<'EOT';
44 Enter message for Samba clients of this host
45 (terminated with single '.' or end of file):
46 EOT
48 while (<>) {
49 last if /^\.$/;
50 push(@message, $_);
53 else { # keep quiet and read message from stdin
54 @message = <>;
57 foreach(@clients) {
58 ## print "To $_:\n";
59 if (open(SENDMSG,"|$smbshout $_")) {
60 print SENDMSG @message;
61 close(SENDMSG);
63 else {
64 warn "Cannot notify $_ with $smbshout:\n$!\n";
68 exit 0;