Running up to X commands in parallel

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP












3















I'm running something like this:



find . -maxdepth 1 -type f -note -iname "*.gpg" | sort | while read file ; do
echo "Encrypting $file..."
gpg --trust-model always --recipient "me@myself.com" --output "$file.gpg"
--encrypt "$file" && rm "$file"
done


This runs great, but it seems that GPG is not optimized to use multiple cores for an encryption operation. The files I'm encrypting are about 2GB in size and I have quite a bit of them. I'd like to be able to run X jobs in parallel to encrypt the files and then remove them. How can I do this, setting a limit to, say, 8 jobs at a time?










share|improve this question




























    3















    I'm running something like this:



    find . -maxdepth 1 -type f -note -iname "*.gpg" | sort | while read file ; do
    echo "Encrypting $file..."
    gpg --trust-model always --recipient "me@myself.com" --output "$file.gpg"
    --encrypt "$file" && rm "$file"
    done


    This runs great, but it seems that GPG is not optimized to use multiple cores for an encryption operation. The files I'm encrypting are about 2GB in size and I have quite a bit of them. I'd like to be able to run X jobs in parallel to encrypt the files and then remove them. How can I do this, setting a limit to, say, 8 jobs at a time?










    share|improve this question


























      3












      3








      3








      I'm running something like this:



      find . -maxdepth 1 -type f -note -iname "*.gpg" | sort | while read file ; do
      echo "Encrypting $file..."
      gpg --trust-model always --recipient "me@myself.com" --output "$file.gpg"
      --encrypt "$file" && rm "$file"
      done


      This runs great, but it seems that GPG is not optimized to use multiple cores for an encryption operation. The files I'm encrypting are about 2GB in size and I have quite a bit of them. I'd like to be able to run X jobs in parallel to encrypt the files and then remove them. How can I do this, setting a limit to, say, 8 jobs at a time?










      share|improve this question
















      I'm running something like this:



      find . -maxdepth 1 -type f -note -iname "*.gpg" | sort | while read file ; do
      echo "Encrypting $file..."
      gpg --trust-model always --recipient "me@myself.com" --output "$file.gpg"
      --encrypt "$file" && rm "$file"
      done


      This runs great, but it seems that GPG is not optimized to use multiple cores for an encryption operation. The files I'm encrypting are about 2GB in size and I have quite a bit of them. I'd like to be able to run X jobs in parallel to encrypt the files and then remove them. How can I do this, setting a limit to, say, 8 jobs at a time?







      scripting gpg parallelism






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Sep 25 '17 at 0:23









      Jeff Schaller

      42k1156133




      42k1156133










      asked Jun 24 '13 at 16:49









      Naftuli KayNaftuli Kay

      12.5k56159256




      12.5k56159256




















          3 Answers
          3






          active

          oldest

          votes


















          4














          If you install the GNU Parallel tool you can make pretty easy work of what you're trying to accomplish:



          $ find . -maxdepth 1 -type f -note -iname "*.gpg" | sort | 
          parallel --gnu -j 8 --workdir $PWD '
          echo "Encrypting ...";
          gpg --trust-model always
          --recipient "me@myself.com" --output ".gpg"
          --encrypt "" && rm ""
          '


          details



          The above is taking the output of find and running it through to parallel, and running 8 at a time. Everywhere there's an occurrence of the filenames that are being passed through from find will replace the in those spots.



          References



          • Running shell script in parallel





          share|improve this answer

























          • What's with the hanging apostrophe at the end? Is it missing a starting apostrophe?

            – Naftuli Kay
            Jun 24 '13 at 17:43











          • @TKKocheran - did that work for you?

            – slm
            Jun 24 '13 at 17:55











          • This is what I'm running, and this is the output I'm seeing. Not working yet :-|

            – Naftuli Kay
            Jun 24 '13 at 18:08











          • What if you move the sudo outside of the find? Make it a sudo -i find ... I don't think you can pipe to sudo in that manner. You could do this: echo "cmd1" | sudo bash.

            – slm
            Jun 24 '13 at 18:20







          • 1





            Looks like I got pwnt with this problem.

            – Naftuli Kay
            Jun 24 '13 at 18:32


















          4














          You might want to look at gnu parallel and its --semaphore option. From the documentation:




          --semaphore



          Work as a counting semaphore. --semaphore will cause GNU parallel to start command in the background. When the number of simultaneous jobs is reached, GNU parallel will wait for one of these to complete before starting another command.




          You use --jobs 8 to limit the number of jobs to 8. You can pipe the output of sort into parallel like you would do with xargs.
          sem is an alias for parallel --semaphore






          share|improve this answer






























            0














            I have written an easy-to-use Perl script that allows to control the maximum number commands that are run at the same time: https://github.com/matmu/parallelize_cmds



            Might be of interest for you.






            share|improve this answer






















              Your Answer








              StackExchange.ready(function()
              var channelOptions =
              tags: "".split(" "),
              id: "106"
              ;
              initTagRenderer("".split(" "), "".split(" "), channelOptions);

              StackExchange.using("externalEditor", function()
              // Have to fire editor after snippets, if snippets enabled
              if (StackExchange.settings.snippets.snippetsEnabled)
              StackExchange.using("snippets", function()
              createEditor();
              );

              else
              createEditor();

              );

              function createEditor()
              StackExchange.prepareEditor(
              heartbeatType: 'answer',
              autoActivateHeartbeat: false,
              convertImagesToLinks: false,
              noModals: true,
              showLowRepImageUploadWarning: true,
              reputationToPostImages: null,
              bindNavPrevention: true,
              postfix: "",
              imageUploader:
              brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
              contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
              allowUrls: true
              ,
              onDemand: true,
              discardSelector: ".discard-answer"
              ,immediatelyShowMarkdownHelp:true
              );



              );













              draft saved

              draft discarded


















              StackExchange.ready(
              function ()
              StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f80514%2frunning-up-to-x-commands-in-parallel%23new-answer', 'question_page');

              );

              Post as a guest















              Required, but never shown

























              3 Answers
              3






              active

              oldest

              votes








              3 Answers
              3






              active

              oldest

              votes









              active

              oldest

              votes






              active

              oldest

              votes









              4














              If you install the GNU Parallel tool you can make pretty easy work of what you're trying to accomplish:



              $ find . -maxdepth 1 -type f -note -iname "*.gpg" | sort | 
              parallel --gnu -j 8 --workdir $PWD '
              echo "Encrypting ...";
              gpg --trust-model always
              --recipient "me@myself.com" --output ".gpg"
              --encrypt "" && rm ""
              '


              details



              The above is taking the output of find and running it through to parallel, and running 8 at a time. Everywhere there's an occurrence of the filenames that are being passed through from find will replace the in those spots.



              References



              • Running shell script in parallel





              share|improve this answer

























              • What's with the hanging apostrophe at the end? Is it missing a starting apostrophe?

                – Naftuli Kay
                Jun 24 '13 at 17:43











              • @TKKocheran - did that work for you?

                – slm
                Jun 24 '13 at 17:55











              • This is what I'm running, and this is the output I'm seeing. Not working yet :-|

                – Naftuli Kay
                Jun 24 '13 at 18:08











              • What if you move the sudo outside of the find? Make it a sudo -i find ... I don't think you can pipe to sudo in that manner. You could do this: echo "cmd1" | sudo bash.

                – slm
                Jun 24 '13 at 18:20







              • 1





                Looks like I got pwnt with this problem.

                – Naftuli Kay
                Jun 24 '13 at 18:32















              4














              If you install the GNU Parallel tool you can make pretty easy work of what you're trying to accomplish:



              $ find . -maxdepth 1 -type f -note -iname "*.gpg" | sort | 
              parallel --gnu -j 8 --workdir $PWD '
              echo "Encrypting ...";
              gpg --trust-model always
              --recipient "me@myself.com" --output ".gpg"
              --encrypt "" && rm ""
              '


              details



              The above is taking the output of find and running it through to parallel, and running 8 at a time. Everywhere there's an occurrence of the filenames that are being passed through from find will replace the in those spots.



              References



              • Running shell script in parallel





              share|improve this answer

























              • What's with the hanging apostrophe at the end? Is it missing a starting apostrophe?

                – Naftuli Kay
                Jun 24 '13 at 17:43











              • @TKKocheran - did that work for you?

                – slm
                Jun 24 '13 at 17:55











              • This is what I'm running, and this is the output I'm seeing. Not working yet :-|

                – Naftuli Kay
                Jun 24 '13 at 18:08











              • What if you move the sudo outside of the find? Make it a sudo -i find ... I don't think you can pipe to sudo in that manner. You could do this: echo "cmd1" | sudo bash.

                – slm
                Jun 24 '13 at 18:20







              • 1





                Looks like I got pwnt with this problem.

                – Naftuli Kay
                Jun 24 '13 at 18:32













              4












              4








              4







              If you install the GNU Parallel tool you can make pretty easy work of what you're trying to accomplish:



              $ find . -maxdepth 1 -type f -note -iname "*.gpg" | sort | 
              parallel --gnu -j 8 --workdir $PWD '
              echo "Encrypting ...";
              gpg --trust-model always
              --recipient "me@myself.com" --output ".gpg"
              --encrypt "" && rm ""
              '


              details



              The above is taking the output of find and running it through to parallel, and running 8 at a time. Everywhere there's an occurrence of the filenames that are being passed through from find will replace the in those spots.



              References



              • Running shell script in parallel





              share|improve this answer















              If you install the GNU Parallel tool you can make pretty easy work of what you're trying to accomplish:



              $ find . -maxdepth 1 -type f -note -iname "*.gpg" | sort | 
              parallel --gnu -j 8 --workdir $PWD '
              echo "Encrypting ...";
              gpg --trust-model always
              --recipient "me@myself.com" --output ".gpg"
              --encrypt "" && rm ""
              '


              details



              The above is taking the output of find and running it through to parallel, and running 8 at a time. Everywhere there's an occurrence of the filenames that are being passed through from find will replace the in those spots.



              References



              • Running shell script in parallel






              share|improve this answer














              share|improve this answer



              share|improve this answer








              edited May 23 '17 at 12:40









              Community

              1




              1










              answered Jun 24 '13 at 17:25









              slmslm

              252k69530685




              252k69530685












              • What's with the hanging apostrophe at the end? Is it missing a starting apostrophe?

                – Naftuli Kay
                Jun 24 '13 at 17:43











              • @TKKocheran - did that work for you?

                – slm
                Jun 24 '13 at 17:55











              • This is what I'm running, and this is the output I'm seeing. Not working yet :-|

                – Naftuli Kay
                Jun 24 '13 at 18:08











              • What if you move the sudo outside of the find? Make it a sudo -i find ... I don't think you can pipe to sudo in that manner. You could do this: echo "cmd1" | sudo bash.

                – slm
                Jun 24 '13 at 18:20







              • 1





                Looks like I got pwnt with this problem.

                – Naftuli Kay
                Jun 24 '13 at 18:32

















              • What's with the hanging apostrophe at the end? Is it missing a starting apostrophe?

                – Naftuli Kay
                Jun 24 '13 at 17:43











              • @TKKocheran - did that work for you?

                – slm
                Jun 24 '13 at 17:55











              • This is what I'm running, and this is the output I'm seeing. Not working yet :-|

                – Naftuli Kay
                Jun 24 '13 at 18:08











              • What if you move the sudo outside of the find? Make it a sudo -i find ... I don't think you can pipe to sudo in that manner. You could do this: echo "cmd1" | sudo bash.

                – slm
                Jun 24 '13 at 18:20







              • 1





                Looks like I got pwnt with this problem.

                – Naftuli Kay
                Jun 24 '13 at 18:32
















              What's with the hanging apostrophe at the end? Is it missing a starting apostrophe?

              – Naftuli Kay
              Jun 24 '13 at 17:43





              What's with the hanging apostrophe at the end? Is it missing a starting apostrophe?

              – Naftuli Kay
              Jun 24 '13 at 17:43













              @TKKocheran - did that work for you?

              – slm
              Jun 24 '13 at 17:55





              @TKKocheran - did that work for you?

              – slm
              Jun 24 '13 at 17:55













              This is what I'm running, and this is the output I'm seeing. Not working yet :-|

              – Naftuli Kay
              Jun 24 '13 at 18:08





              This is what I'm running, and this is the output I'm seeing. Not working yet :-|

              – Naftuli Kay
              Jun 24 '13 at 18:08













              What if you move the sudo outside of the find? Make it a sudo -i find ... I don't think you can pipe to sudo in that manner. You could do this: echo "cmd1" | sudo bash.

              – slm
              Jun 24 '13 at 18:20






              What if you move the sudo outside of the find? Make it a sudo -i find ... I don't think you can pipe to sudo in that manner. You could do this: echo "cmd1" | sudo bash.

              – slm
              Jun 24 '13 at 18:20





              1




              1





              Looks like I got pwnt with this problem.

              – Naftuli Kay
              Jun 24 '13 at 18:32





              Looks like I got pwnt with this problem.

              – Naftuli Kay
              Jun 24 '13 at 18:32













              4














              You might want to look at gnu parallel and its --semaphore option. From the documentation:




              --semaphore



              Work as a counting semaphore. --semaphore will cause GNU parallel to start command in the background. When the number of simultaneous jobs is reached, GNU parallel will wait for one of these to complete before starting another command.




              You use --jobs 8 to limit the number of jobs to 8. You can pipe the output of sort into parallel like you would do with xargs.
              sem is an alias for parallel --semaphore






              share|improve this answer



























                4














                You might want to look at gnu parallel and its --semaphore option. From the documentation:




                --semaphore



                Work as a counting semaphore. --semaphore will cause GNU parallel to start command in the background. When the number of simultaneous jobs is reached, GNU parallel will wait for one of these to complete before starting another command.




                You use --jobs 8 to limit the number of jobs to 8. You can pipe the output of sort into parallel like you would do with xargs.
                sem is an alias for parallel --semaphore






                share|improve this answer

























                  4












                  4








                  4







                  You might want to look at gnu parallel and its --semaphore option. From the documentation:




                  --semaphore



                  Work as a counting semaphore. --semaphore will cause GNU parallel to start command in the background. When the number of simultaneous jobs is reached, GNU parallel will wait for one of these to complete before starting another command.




                  You use --jobs 8 to limit the number of jobs to 8. You can pipe the output of sort into parallel like you would do with xargs.
                  sem is an alias for parallel --semaphore






                  share|improve this answer













                  You might want to look at gnu parallel and its --semaphore option. From the documentation:




                  --semaphore



                  Work as a counting semaphore. --semaphore will cause GNU parallel to start command in the background. When the number of simultaneous jobs is reached, GNU parallel will wait for one of these to complete before starting another command.




                  You use --jobs 8 to limit the number of jobs to 8. You can pipe the output of sort into parallel like you would do with xargs.
                  sem is an alias for parallel --semaphore







                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Jun 24 '13 at 17:20









                  AnthonAnthon

                  60.9k17103166




                  60.9k17103166





















                      0














                      I have written an easy-to-use Perl script that allows to control the maximum number commands that are run at the same time: https://github.com/matmu/parallelize_cmds



                      Might be of interest for you.






                      share|improve this answer



























                        0














                        I have written an easy-to-use Perl script that allows to control the maximum number commands that are run at the same time: https://github.com/matmu/parallelize_cmds



                        Might be of interest for you.






                        share|improve this answer

























                          0












                          0








                          0







                          I have written an easy-to-use Perl script that allows to control the maximum number commands that are run at the same time: https://github.com/matmu/parallelize_cmds



                          Might be of interest for you.






                          share|improve this answer













                          I have written an easy-to-use Perl script that allows to control the maximum number commands that are run at the same time: https://github.com/matmu/parallelize_cmds



                          Might be of interest for you.







                          share|improve this answer












                          share|improve this answer



                          share|improve this answer










                          answered Feb 1 at 11:11









                          Matthias MunzMatthias Munz

                          1012




                          1012



























                              draft saved

                              draft discarded
















































                              Thanks for contributing an answer to Unix & Linux Stack Exchange!


                              • Please be sure to answer the question. Provide details and share your research!

                              But avoid


                              • Asking for help, clarification, or responding to other answers.

                              • Making statements based on opinion; back them up with references or personal experience.

                              To learn more, see our tips on writing great answers.




                              draft saved


                              draft discarded














                              StackExchange.ready(
                              function ()
                              StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f80514%2frunning-up-to-x-commands-in-parallel%23new-answer', 'question_page');

                              );

                              Post as a guest















                              Required, but never shown





















































                              Required, but never shown














                              Required, but never shown












                              Required, but never shown







                              Required, but never shown

































                              Required, but never shown














                              Required, but never shown












                              Required, but never shown







                              Required, but never shown






                              Popular posts from this blog

                              How to check contact read email or not when send email to Individual?

                              Displaying single band from multi-band raster using QGIS

                              How many registers does an x86_64 CPU actually have?