cored has asked for the wisdom of the Perl Monks concerning the following question:

Hi, guys this is my first post and im new in perl too. So don't be hard with me :) Well, im working on a script that send messages on the network to 10 machines, the machines are in windows 2000 and im using linux as a server my script goes something like this:
#!/usr/bin/perl -w use strict; my $msg = "Please turn off your machines"; my $cont = 1; while($cont<=10){ system("echo $msg | smbclient -M mach-${cont}"); $cont=$cont+1; }
I want to know if exist a module or something that make this in a easy way, i search on cpan.org but i did not find nothing. There's more than one way to do it :)

Replies are listed 'Best First'.
Re: Sending multiples network messages
by robartes (Priest) on Oct 10, 2002 at 21:35 UTC
    Have a look at Filesys::SmbClientParser. The sendWinpopupMessage method seems to be just your ticket:
    use strict; use Filesys::SmbClientParser; my $path="/path/to/smbclient"; my $target="kasbah"; my $smb=Filesys::SmbClientParser->new($path, { user => "camel", passwo +rd => "humps" }); $smb->sendWinpopupMessage($target, "My tailor is rich.");
    I don't have the module installed (got the above from the online docs), nor have I access to a handy Windows box to test, so the above code comes with the usual guarantee for untested code: use at your own risk. Or, as the case may be, at your camel's risk.

    Untested code fun aside, the module should save you an ugly and expensive system() call.

    CU
    Robartes-

    Update: Fixed small booboo: forgot to define $target. Then again, this is untested code, so there :).

Re: Sending multiples network messages
by talexb (Chancellor) on Oct 10, 2002 at 21:46 UTC

    I would probably simplify the code to this:

    #!/usr/bin/perl -w use strict; my $msg = "Please turn off your machines"; for ( 1..10 ) { system ( "echo $msg | smbclient -M mach-$_" ); }

    This assumes that your machine's NETBIOS names run from mach-1 to mach-10. it seems fairly simple .. why do you think you need a CPAN module to make this simpler?

    --t. alex
    but my friends call me T.