Hello,

Take a look at Net::OpenSSH or other cpan ssh modules.

It is not exactly what do you want to do (perl will running in this case in your computer and not in remote), but I hope it helps.

It can be useful in many environments, like:

  • You don't have the same perl version in all your hosts
  • You want to parse some remote file or some remote command output
  • You want to write remote files with some info
  • See this example which is like a first attemp to solve your problem (cat script.pl | perl thisexample user@host parameters):

    #!/usr/bin/perl -w use strict; use Net::OpenSSH; my $ssh = Net::OpenSSH->new($ARGV[0]); $ssh->error and die "Couldn't establish SSH connection: ". $ssh->error; shift; my (@args)=@_; shift while (@ARGV!=0); my $command=""; while (<>) { $command.=$_; } $ssh->system("perl - <<EOS @args $command; EOS ");

    For solve this specific issue, I prefer the response that Anonymous monk give you before (Re^2: run perl script with cmd line in shell), it is clearest.

    Regards,

    In reply to Re: run perl script with cmd line in shell by i5513
    in thread run perl script with cmd line in shell by Anonymous Monk

    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.