Running up to X commands in parallel
Clash Royale CLAN TAG#URR8PPP
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
add a comment |
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
add a comment |
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
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
scripting gpg parallelism
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
add a comment |
add a comment |
3 Answers
3
active
oldest
votes
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
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 thesudo
outside of thefind
? Make it asudo -i find ..
. I don't think you can pipe tosudo
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
|
show 6 more comments
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
add a comment |
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.
add a comment |
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
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
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
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 thesudo
outside of thefind
? Make it asudo -i find ..
. I don't think you can pipe tosudo
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
|
show 6 more comments
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
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 thesudo
outside of thefind
? Make it asudo -i find ..
. I don't think you can pipe tosudo
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
|
show 6 more comments
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
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
edited May 23 '17 at 12:40
Community♦
1
1
answered Jun 24 '13 at 17:25
slm♦slm
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 thesudo
outside of thefind
? Make it asudo -i find ..
. I don't think you can pipe tosudo
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
|
show 6 more comments
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 thesudo
outside of thefind
? Make it asudo -i find ..
. I don't think you can pipe tosudo
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
|
show 6 more comments
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
add a comment |
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
add a comment |
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
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
answered Jun 24 '13 at 17:20
AnthonAnthon
60.9k17103166
60.9k17103166
add a comment |
add a comment |
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.
add a comment |
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.
add a comment |
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.
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.
answered Feb 1 at 11:11
Matthias MunzMatthias Munz
1012
1012
add a comment |
add a comment |
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.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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