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

Hi,

Perhaps this is not an appropriate question, I am really not sure. But, especially with the many mods out there, my guess is, it is.

Anyway, I wrote an html form and perl cgi script. The next phase of the application needs for another server to have some text, based in part on the form entry, passed to it and to have another script executed (script on the other server side, the side where the text needs to be passed). This is something I have never done before and I am wondering if there is an approach and (if so) what it is, including mods to want to use.

Not sure if it matters, but they are unix servers.

Thanks in advance!

Tony
  • Comment on How To Pass To Another Server and Spawn Another Script

Replies are listed 'Best First'.
Re: How To Pass To Another Server and Spawn Another Script
by Tanktalus (Canon) on Oct 25, 2006 at 20:39 UTC

    Let me get this straight. We have a client attach to Server A (via http). During the handling of this request, it is determined that a connection to Server B is required to run some other program. Is that right?

    So the question is - what protocol to use? That will entirely drive the module(s) that you can use/need. Do you connect via telnet, or ssh, or rsh, or something else? Perhaps Server B is also running a webserver, in which case your CGI script can just use LWP to connect and pass stuff in and get the returns back. But you have to determine how you want to make these connections.

      Thanks, Tank. I'll reply to the other reply as a general reply to both of you.
Re: How To Pass To Another Server and Spawn Another Script
by jeffa (Bishop) on Oct 25, 2006 at 21:18 UTC

    How i have handled this in the past (UNIX, by the way) is to set up a server on the remote box that will run the remote commands. The client passes a string to the server via Sockets, the server parses that string (ensures it is a safe command to run) and forks a child process to run the command. It then waits on the child process and collects exit info when the child is reaped and passes the data back to the client over the socket.

    jeffa

    L-LL-L--L-LL-L--L-LL-L--
    -R--R-RR-R--R-RR-R--R-RR
    B--B--B--B--B--B--B--B--
    H---H---H---H---H---H---
    (the triplet paradiddle with high-hat)
    
      Hi Tank and jeffa,

      Tank, you have exposed some of my ignorance of protocols and their capabilities. I know I can use scp to easily bring the information over. That's about it.

      jeffa, I think you are hitting on what I need to do and in fact your explanation does more than I need. Basically, I could sure use that Socket part to pass information, as well as the ability for the remote server to fetch that value and spawn a simple script. It doesn't need to give any information back to the source server.

      Well, I guess I'll study the Socket mod and see how to pass the info and spawn a program.

      Thanks!

      Tony
Re: How To Pass To Another Server and Spawn Another Script
by nedals (Deacon) on Oct 26, 2006 at 00:18 UTC

    Like Tanktalus mentioned, sound like a job for LWP.

    Simply post the required form data to the ServerB via LWP. The script on ServerB will need to send some sort of response which you can process in the script on ServerA

    my $ua = LWP::UserAgent->new(); my $response = $ua->post( $url, { 'field1'=>$data1, 'field2'=>$data2, etc ); if ($response->is_success) { my $accepted = $response->content; #process data } else { #error }
      Thanks

      I'll bone up on this LWP method.

      Tony
Re: How To Pass To Another Server and Spawn Another Script
by doowah2004 (Monk) on Oct 25, 2006 at 22:17 UTC
    I am not to sure of what you are trying to do. If you are just trying to send a file somewhere and have another script do some manipulations on it, and you do not want any response back, then an easy thing to do (especial on unix) would be to use ftp to push the file and set up a cron job to periodically run the script.
    For example you can have an import folder that the script would scan, if it finds a file it would do the manipulations and move it to a different folder. The cron job simply runs the script in given intervals that you determine adequate.
    This is a very basic solution, but a common one with lots of documentation.

    That being said, if you are looking for real-time type response then streaming the file via socks would be a better path.
Re: How To Pass To Another Server and Spawn Another Script
by andyford (Curate) on Oct 26, 2006 at 03:02 UTC
    If you're in a business environment, perhaps you should ask around. Maybe someone already has some preferred methods or infrastructure already in place. It's good to build on what's already implemented so that your "IT" infrastructure doesn't grow too many heads.

    andyford
    or non-Perl: Andy Ford