Reputation: 1562
Could you please help me with any hint about the below issue?
i have to send a command to a host (the command needs lot of time to execute and creates a file):
ssh uname1@host1 ssh uname2@host2 'command1'
after this command gets executed i need to zip the file created
ssh uname1@host1 ssh uname2@host2 'gzip file1'
Than do the same thing for another host
ssh uname3@host3 ssh uname4@host4 'command1'
ssh uname1@host1 ssh uname2@host2 'gzip file2'
Is it possible to run both this commands in parallel in order to save time for script execution? thank you in advance.
Upvotes: 1
Views: 111
Reputation: 34297
try something like
ssh uname2@host2 'command1 && gzip file1' &
ssh uname2@host3 'command1 && gzip file1' &
ssh uname2@host4 'command1 && gzip file1' &
You can put all the commands in a file on the host you start from
&&
in this context works like ;
but the second command is only executed if the first works
Upvotes: 4
Reputation: 184975
Simply do:
ssh uname1@host1 ssh uname2@host2 'command1; gzip file1'
and if the gzip should be run only is the first command is a success, then :
ssh uname1@host1 ssh uname2@host2 'command1 && gzip file1'
The second command will be launched after the first one.
Upvotes: 2