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
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.
On Linux, there are three ways to run multiple commands in a terminal: The Semicolon (;) operator. The Logical OR (||) operator. The Logical AND (&&) operator.
Yes, you can execute many shells simultaneously as you want.
Replace
/usr/bin/sshpass ...
with
/usr/bin/sshpass ... &
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With