Have you tried simply running the Perl script via the ssh executable?

ssh account@remote.machine.intern -c 'perl -w whatever.pl'

If you want to launch that from Perl, the following could work on both, Windows and Linux, presuming you have passwordless keys and/or ssh-agent running to handle the authentication:

use strict; my @machines = qw( worker1 worker2 worker3 ); my @cmd = @ARGV; my $ssh = 'ssh'; for my $machine (@machines) { my @commandline = $ssh, $machine, '-c', @cmd; print "[$machine] @commandline\n"; system(@commandline) == 0 or warn "Couldn't launch >>@cmd<< on $machine: $! / $?"; };

The above will wait for each task on each machine to finish. If you do want to run all tasks in parallel, you will have to spawn the processes differently, depending on how your OS lets you spawn processes in parallel. On Windows, use system( 1, ...) or system('start',...), and on Unixish shells, you can likely use the "background operator" &:

... # Linux parallel, watch out for quoting with your shell! system("@commandline &") == 0 ...

Windows is nicer here but has the drawback that you can only run 63 processes that way in parallel unless you compile your own Perl:

... # Windows parallel, watch out for quoting with your shell! system(1, @commandline) == 0 ...

In reply to Re^4: Invoke a perl script on the remote machine. by Corion
in thread Invoke a perl script on the remote machine. by isha

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.