Running jobs through ssh (linux/osx)

2019-09-08 14:58发布

问题:

I was wondering if it was possible to execute jobs via ssh. In particular I have a different list of input files on a number of machines that all have the same executable in the same place. Is there some command which means I dont have to move from machine to machine using ssh and set them running individually. The sort of thing I had in mind would be something like:

ssh RemoteMachine1:./Executable ~/Inputfile_1 ssh RemoteMachine2:./Executable ~/Inputfile_2

which could be run from my host machine? Thanks in advance Jack

回答1:

Try using Fabric.

"Fabric is a Python (2.5 or higher) library and command-line tool for streamlining the use of SSH for application deployment or systems administration tasks."



回答2:

If you can write Perl, try Net::OpenSSH::Parallel.

For instance:

my %file = (host1 => file1,
             host2 => file2,
             ...);

my $pssh = Net::OpenSSH::Parallel->new();

for my $host (keys %files) {
    $pssh->add_host($host);
    $pssh->push($host, 'cmd',
                {stdout_file => "$host.out"},
                './Executable', $file{$host});

}

$pssh->run


回答3:

You usually can run the batch command thru ssh ; read more about batch command and batch processing.

You might also be interested by MPI or DSH or SQS