This commit was generated by cvs2svn to compensate for changes in r4,
[kai/samba-autobuild/.git] / examples / misc / wall.perl
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>
10 #
11 #=============================================================================
12 $smbstatus = "/usr/local/bin/smbstatus";
13 $smbclient = "/usr/local/bin/smbclient";
14
15 print STDOUT "\nEnter message for Samba clients of this host\n";
16 print STDOUT "(terminated with single '.' or end of file):\n";
17
18 while ( <STDIN> ) {
19         /^\.$/ && last;
20         push(@message,  $_);
21 }
22
23 if ( $ARGV[0] ne "" ) {
24         $debug && print STDOUT "Was given args: \n\t @ARGV\n";
25         foreach $client ( @ARGV ) {
26                 $pcclient{$client} = $client;
27         }
28 } else {
29         open( PCLIST, "$smbstatus | /bin/awk '/^[a-z]/ {print $5}' | /bin/sort | /bin/uniq|");
30         while ( <PCLIST> ) {
31                 /^[a-z]+[a-z0-9A-Z-_]+.+/ || next;
32                 ($share, $user, $group, $pid, $client, @junk) = split;
33                 $pcclient{$client} = $client;
34         }
35         close(PCLIST);
36 }
37
38 foreach $pc ( keys(%pcclient) ) {
39         print STDOUT "Sending message ";
40         $debug && print STDOUT " <@message> \n";
41         print STDOUT "To <$pc>\n";
42         open(SENDMSG,"|$smbclient -M $pc") || next;
43         print SENDMSG @message;
44         close(SENDMSG);
45 }