in reply to Connecting to a remote host

If script 2 can be a CGI just send it the values by calling it with the appropriate query string:

# in script 1 use LWP::Simple; my %values = ( foo => 'some val', bar => 'other val' ); my $script2 = 'http://somewhere.com/cgi-bin/script2.pl'; my $query_string = join '&', map { '$_=' . escapeURL($values{$_}) } ke +ys %values; my $res = get( $script2 . '?' . $query_string ); print $res; sub escapeURL { my $encode = shift; return undef unless defined $encode; $encode=~s/([^a-zA-Z0-9_.-])/uc sprintf("%%%02x",ord($1))/eg; return $encode; } # in script 2 use CGI; my $q = new CGI; print $q->header; # prove we got it.... print "<p>Got: $_ " . $q->param($_) for $q->param(); # print stuff to file....

Alternatively use Net::SSH or IO::Socket or shell out to system('ssh', 'user@machine', 'script', 'data' ). There are lotsa ways to do it.

cheers

tachyon

s&&rsenoyhcatreve&&&s&n.+t&"$'$`$\"$\&"&ee&&y&srve&&d&&print

Replies are listed 'Best First'.
Re: Re: Connecting to a remote host
by rupesh (Hermit) on Apr 04, 2003 at 11:53 UTC
    Hey tachyon,
    Thanks for the info mate!...
    but listen, regarding the script you had posted, how do you know whether the second script is being executed or not??
    I tried to print some data into a file in the remote machine, but the file ain't getting created!
    'twould be great if yoo could help...thanks!

      You should be able to call script2.pl like: http://mysite.com/cgi-bin/script2.pl?sent=Hello+World by typing that into the browser Address bar, and it should print something like Got sent = 'Hello World' Can't remember what format I had it printing but it was something like that. Once it works ie shows you what you sent it in the query string it will do the same when you call it using LWP::Simple get() method with the same URL. You can then just get it to print 'OK' which you then get back in $res:

      use LWP::Simple; my $res = get( 'http://mysite.com/cgi-bin/script2.pl?sent=Hello+World' + ); if ( $res eq 'OK' ) { # blah }

      cheers

      tachyon

      s&&rsenoyhcatreve&&&s&n.+t&"$'$`$\"$\&"&ee&&y&srve&&d&&print

        Hi,
        Thanks again...
        but, the fact is this: i have a couple of servers at another place. I have a set of perl scripts each copied into these servers and one has to run it in the CMD to execute.

        What i want is, instead of waiting for someone to explicitly execute it one those servers( 8 of 'em), would like to exececute it from here using a socket - server, client method.
        These are the inputs required :
        machine name, location of script.
        and the script has to do the following:
        get some inputs from the user, and pass these inputs to a script on the server.

        The script on the server, works on these inputs in the database on that server, and populates a .csv file.
        I can later copy that .csv file and generate reports.
        All these functions are done via the command line. All my perl scripts are converted to exe using perl2exe, so that perl need not be installed in the server.

        So shortly, double click on script1, enter data, the data is sent to script2 in some server somewhere, after sometime a text file is created on that server. Is this possible?...... THanks a ton......