Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

Re: run perl script with cmd line in shell

by i5513 (Monk)
on Apr 16, 2012 at 22:43 UTC ( #965407=note: print w/ replies, xml ) Need Help??


in reply to run perl script with cmd line in shell

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,


    Comment on Re: run perl script with cmd line in shell
    Download Code

    Log In?
    Username:
    Password:

    What's my password?
    Create A New User
    Node Status?
    node history
    Node Type: note [id://965407]
    help
    Chatterbox?
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others browsing the Monastery: (9)
    As of 2014-08-20 19:07 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      The best computer themed movie is:











      Results (122 votes), past polls