Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Running a Perl script on another domain .... 1

Status
Not open for further replies.

poplarman

IS-IT--Management
Dec 15, 2001
12
US

From within a perl script I want to run a perl script on another domain for which I have upload and access rights and then, if possible, check the result and then continue with the original calling script.

Is this possible please?

Pop
 
I think this would only work if you set up a VPN (virtual private network) that allowed you to access and connect to the machines and drives on the remote network.

There may be some fancy convoluted way of using cutting edge stuff like SOAP (Simple Object Access Protocol) to tunnel through the http port, but you'd have to find an expert to advise you whether that would work and how to set it up.

However, I think SOAP would require using a language that compiles (i.e. Visual Basic or Visual C++) to create a COM object. Perl is a scripting language that doesn't compile.

Hope this helps.
 
Thanks,

I was beginning to suspect that this was not so simple.

Pop
 
on your remote server, run a web server
on that web server, have a particular URL call a perl script
call that URL from your local server Mike
michael.j.lacey@ntlworld.com
Email welcome if you're in a hurry or something -- but post in tek-tips as well please, and I will post my reply here as well.
 
I've done the kind of thing you want to do before, and Mike has the gist of how it's done. The perl script I called on the different domain was set up as a "cgi program". It was written to be called like a cgi program, passed it's arguments like a cgi program, and return a "html page" that contained only minimal html, and the return values I needed as part of that "page" that I could parse out using regular expressions. Then I used the LWP module to call it. Tracy Dryden
tracy@bydisn.com

Meddle not in the affairs of dragons,
For you are crunchy, and good with mustard.
 
Tracy,

Thanks for that. Is it possible you can give me an example of the code that makes the call and the parsing?

Pop
 
Here's the code for the subroutine I used to call the remote functions:
Code:
#---------------------------------------------------------------------
# WebMallRemoteFunc
#---------------------------------------------------------------------
# Perform some webmall function on the 1webstreet.net server.
# Since this is a different server, we use an http request to call
# a cgi program remotely and parse the returned "web page".
#
# Parameters: Function, webmall name
#
# Returns: Ref to hash containing returned data (parameters passed,
#          error message, return code.
#---------------------------------------------------------------------

sub WebMallRemoteFunc {

local($func, $webmall, $newmall) = @_;

%Ret = ();

my $domain = "[URL unfurl="true"]http://www.xxx.com";[/URL]
my $cgidir = "/cgi-local";
my $cgipgm = "WebMallRemoteFuncs.pl";
my %form = ();

if ( lc($func) ne "rename" ) {
	%form = ( FUNC => $func, WebMall => $webmall );
} else {
	%form = ( FUNC => $func, WebMall => $webmall, NewMall => $newmall );
}

use URI::URL;
use LWP::UserAgent;
my $ua = new LWP::UserAgent;

my $tmpurl = url("http:");
$tmpurl->query_form(%form);
my $req = new HTTP::Request 'POST', "$domain$cgidir/$cgipgm";
$req->content_type('application/x-[URL unfurl="true"]www-form-urlencoded');[/URL]
$req->content($tmpurl->equery);

print &quot;<b>WebMallRemoteFunc: Content: </b>&quot; . $tmpurl->equery . &quot;<br><br>&quot; if $debug;
my $res = $ua->request($req);
if ( $res->is_success ) {
	$returnData = $res->as_string;
} else {
	$Ret{'Error'} = &quot;HTTP error: &quot; . $res->code . &quot; &quot; . $res->message;
	$Ret{'Return'} = 0;
	print &quot;<b>WebMallRemoteFunc: Error: </b>&quot; . $Ret{'Error'} . &quot;<br><br>&quot; if $debug;
	return \%Ret;
}

print &quot;<b>WebMallRemoteFunc: Returned Data: </b><br><pre>$returnData</pre><br><br>&quot; if $debug;

# Parse the data returned in the &quot;web page&quot; and return it.
$PassedHeader = 0;
@returnData = split('\n', $returnData);
for (@returnData) {
	$PassedHeader = 1 if /\A\Z/;
	next unless $PassedHeader;
	$Ret{$1} = $2 if /\A(.+):\s+(.+)\Z/;
}

if ( $debug ) {
	print &quot;<b>WebMallRemoteFunc: Returning hash: </b><br><pre>&quot;;
	while ( ($key,$val) = each %Ret ) {
		print &quot;$key => $val\n&quot;;
	}
	print &quot;</pre><br>&quot;;
}
return \%Ret;

} # WebMallRemoteFunc
Tracy Dryden
tracy@bydisn.com

Meddle not in the affairs of dragons,
For you are crunchy, and good with mustard.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top