The solution here depends on how much work you want to do and what permissions you have on Machine B. If you can SSH to it then Net::OpenSSH to execute commands is the simplest and quickest way to get this done. Other options will require you to put some code on Machine B.

One easy to implement but heavier(in terms of system resources) option is to run a webservice on a unoccupied port number using Dancer or Catalyst etc. on Machine B and let the webservice run the commands and return the result to you.

Third option albeit insecure in its bare form is to write a program using one of the event handling systems like AnyEvent, EV or POE to create a listening network socket on Machine B. This requires familiarity with event loops.

Make a socket connection from Machine A to Machine B when required and send the command to run. The Target Machine can then process the command and stream the result back to the Machine A on the same socket.

You can use POE::Component::Server::TCP on Machine B and POE::Component::Client::TCP on Machine A.
Note that on Machine B the server must run with the same permissions that you wish to grant for running the commands(You dont want a random person running "sudo rm -rf /"). Of course a better assurance against abuse would be to write some code in the server to decide weather to accept a command or not.

HTH
-Shantanu Bhadoria

In reply to Re: How to execute Perl code on remote machine from a local Perl script and process the output/variables in your local Perl script by shantanu_bhadoria
in thread How to execute Perl code on remote machine from a local Perl script and process the output/variables in your local Perl script by dushyant

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.