Skip to content

Instantly share code, notes, and snippets.

@isopropylcyanide
Created March 21, 2020 15:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save isopropylcyanide/10b9ba1548e5129b62b9e9395f3406c6 to your computer and use it in GitHub Desktop.
Save isopropylcyanide/10b9ba1548e5129b62b9e9395f3406c6 to your computer and use it in GitHub Desktop.
Generic function that utilises function arguments to fire commands for a total of `N` times in `M` jobs at a parallel
# Generic function that utilises function arguments to fire commands for a total of `N` times in `M` jobs at a parallel
set -o xtrace
function conc(){
cmd=("${@:3}")
seq 1 "$1" | xargs -n1 -P"$2" "${cmd[@]}"
}
# $ conc N M cmd
# $ conc 10 2 curl --location --request GET 'http://google.com/'
# This will fire `10` curl commands at a max parallelism of two each.
# Adding this function to the `bash_profile` makes it easier.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment