How do i use gnu parallel to run commands simultaneously?



  • To run commands simultaneously you can use GNU parallel.

    You can run multiple commands in the background, but parallels works out how many cores you have and runs one job per core.

    I have a file with multiple commands, for demonstration purposes the commands in file are the same.

    $ cat commands2.txt 
    curl -o bootstrap-salt.sh1 -L https://bootstrap.saltstack.com 
    curl -o bootstrap-salt.sh2 -L https://bootstrap.saltstack.com
    curl -o bootstrap-salt.sh3 -L https://bootstrap.saltstack.com
    curl -o bootstrap-salt.sh4 -L https://bootstrap.saltstack.com
    curl -o bootstrap-salt.sh5 -L https://bootstrap.saltstack.com
    curl -o bootstrap-salt.sh6 -L https://bootstrap.saltstack.com
    curl -o bootstrap-salt.sh7 -L https://bootstrap.saltstack.com
    curl -o bootstrap-salt.sh8 -L https://bootstrap.saltstack.com
    curl -o bootstrap-salt.sh9 -L https://bootstrap.saltstack.com
    curl -o bootstrap-salt.sh10 -L https://bootstrap.saltstack.com
    

    Run two commands at the same time.

    $ parallel --jobs 2  < commands2.txt
    

    Run all ten commands at the same time

    $ parallel --jobs 10 < commands2.txt
    

Log in to reply
 

© Lightnetics 2024