Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I execute parallel "for" loops in Bash?

I have been trying to parallelize the following script, specifically the for loop. How can I do that?

#!/bin/bash
for i in `cat /root/vms`;
do
    /usr/bin/sshpass -p 'test' /usr/bin/ssh -o StrictHostKeyChecking=no \
        -l testuser $i -t 'echo test | sudo -S yum update -y'
done
like image 914
gosatriani Avatar asked Dec 13 '17 06:12

gosatriani


People also ask

How do I run a parallel shell script?

Running Commands in Parallel using Bash Shell The best method is to put all the wget commands in one script, and execute the script. The only thing to note here is to put all these wget commands in background (shell background). See our simple script file below. Notice the & towards the end of each command.

How do I run multiple scripts in parallel Linux?

On Linux, there are three ways to run multiple commands in a terminal: The Semicolon (;) operator. The Logical OR (||) operator. The Logical AND (&&) operator.

Can you run two bash scripts at the same time?

Yes, you can execute many shells simultaneously as you want.


1 Answers

Replace

/usr/bin/sshpass ...

with

/usr/bin/sshpass ... &
like image 120
Cyrus Avatar answered Sep 22 '22 10:09

Cyrus