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

Re: Invoke a perl script on the remote machine.

by fenLisesi (Priest)
on Jun 29, 2007 at 07:04 UTC ( [id://624047]=note: print w/replies, xml ) Need Help??


in reply to Invoke a perl script on the remote machine.

Looks like Net::SSH may help. Cheers.
  • Comment on Re: Invoke a perl script on the remote machine.

Replies are listed 'Best First'.
Re^2: Invoke a perl script on the remote machine.
by tirwhan (Abbot) on Jun 29, 2007 at 07:40 UTC

    Or, even better, look at Net::SSH2 which is actively maintained and actually installs and works on modern platforms(disclaimer: this may be personal bias, but I haven't been able to get Net::SSH to do this for some time now).


    All dogma is stupid.
      Is there any other way other than using Net:SSH2.... I want my script to run in both network... Linux as well as windows. Thanks.

        Have you tried simply running the Perl script via the ssh executable?

        ssh account@remote.machine.intern -c 'perl -w whatever.pl'

        If you want to launch that from Perl, the following could work on both, Windows and Linux, presuming you have passwordless keys and/or ssh-agent running to handle the authentication:

        use strict; my @machines = qw( worker1 worker2 worker3 ); my @cmd = @ARGV; my $ssh = 'ssh'; for my $machine (@machines) { my @commandline = $ssh, $machine, '-c', @cmd; print "[$machine] @commandline\n"; system(@commandline) == 0 or warn "Couldn't launch >>@cmd<< on $machine: $! / $?"; };

        The above will wait for each task on each machine to finish. If you do want to run all tasks in parallel, you will have to spawn the processes differently, depending on how your OS lets you spawn processes in parallel. On Windows, use system( 1, ...) or system('start',...), and on Unixish shells, you can likely use the "background operator" &:

        ... # Linux parallel, watch out for quoting with your shell! system("@commandline &") == 0 ...

        Windows is nicer here but has the drawback that you can only run 63 processes that way in parallel unless you compile your own Perl:

        ... # Windows parallel, watch out for quoting with your shell! system(1, @commandline) == 0 ...
        A reply falls below the community's threshold of quality. You may see it by logging in.
        Is there any other way other than using Net:SSH2.... I want my script to run in both network... Linux as well as windows

        So? libssh2 is cross-platform so I see no issue with using Net::SSH2 with both Linux and Windows (I can't test it on Windows because I don't swing that way, but there should be no problem in principle).

        Sure there are other ways of invoking a script across a network (running it as a CGI comes to mind), but they all need to solve the problem of authentication and confidentiality. ssh does this for you in a comfortable and secure way out of the box why not use it?


        All dogma is stupid.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (7)
As of 2024-04-18 11:20 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found