#!/usr/bin/perl -w # #@(#) smb-wall.pl Description: #@(#) A perl script which allows you to announce whatever you choose to #@(#) a specific user at a PC client currently connected to a Samba Server... #@(#) ...using "smbclient -M" message to winpopup service. #@(#) Skript based of smb_wall.pl by Keith Farrar # #============================================================================= # # Modified by # Heiko Teichmeier # 2003-11-09 # 2003-11-19 0.2.1 # Glauchau/Sa., Germany # use strict; my (@clients,@message,$client,$username,$ARGV); my $smbstatus = "/usr/bin/smbstatus"; my $smbshout = "/usr/bin/smbclient -M"; my $script_name = $0; if ($ARGV[0]) { $username = $ARGV[0]; undef @ARGV; } else { print "No argument at call of program!\n"; print "Usage:\n"; print "======\n"; print "$script_name username\n"; exit 1; } # zum testen des Inhalts der Variablen $username #print "\$username = $username"; open(PCLIST, "$smbstatus |") || die "\$smbstatus failed!.\n$!\n"; while() { last if /^Locked files:/; my @data = split(' ', $_, 6); # do not accept this line if less then six fields next unless $data[5]; my $u_name = $data[1]; next if ($u_name ne $username); $client = $data[4]; next unless $client =~ /[^.]/; # expect 'dot' in a client name next if grep($_ eq $client, @clients); # we want this name once push(@clients, $client); } close(PCLIST); # zum testen des Inhalts der Variablen @client #print "@clients\n"; #exit 1; 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(@clients) { if (open(SENDMSG,"|$smbshout $_")) { print SENDMSG @message; close(SENDMSG); } else { warn "Cannot notify $_ with $smbshout:\n$!\n"; } } exit 0;