Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

Re^3: Invoke a perl script on the remote machine.

by isha (Sexton)
on Jun 29, 2007 at 08:24 UTC ( [id://624062]=note: print w/replies, xml ) Need Help??


in reply to Re^2: Invoke a perl script on the remote machine.
in thread Invoke a perl script on the remote machine.

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.
  • Comment on Re^3: Invoke a perl script on the remote machine.

Replies are listed 'Best First'.
Re^4: Invoke a perl script on the remote machine.
by Corion (Patriarch) on Jun 29, 2007 at 08:35 UTC

    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.
Re^4: Invoke a perl script on the remote machine.
by tirwhan (Abbot) on Jun 29, 2007 at 09:05 UTC
    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.
      Actually I am trying to login from Windows machine(user –abc) to linux machine(user-xyz) using ssh protocol. I have generated the encryption key using Putty Gen & copied the same in the linux machine : $home/.ssh/authentication_key. But still my script is giving the error: - Permission denied (publickey, password, keyboard-interactive). It would be really great if you can help me on this. regards kapila.kohli@gmail.com

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others learning in the Monastery: (5)
As of 2024-04-19 17:23 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found