Skip to content

Instantly share code, notes, and snippets.

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 HakimCassimallyBBC/e2a3180ca287aa572bf347bc30673eff to your computer and use it in GitHub Desktop.
Save HakimCassimallyBBC/e2a3180ca287aa572bf347bc30673eff to your computer and use it in GitHub Desktop.
nit-parallel
#!/bin/bash
# Usage:
#
# nit-parallel [cosmos-running-instances args ...] -- [parallel args ...]
#
# e.g.
#
# ### No piped input: run command on all hosts
# nit-parallel -e test pm-nitro-test-1 -- hostname
#
# ### Piped input, use {} for each input
# nit-parallel -e test pm-nitro-test-1 -- echo {} < list-of-pids
#
# ### remember, after "--" is just passed to parallel, e.g. to ensure in same order:
# seq 5 | ./nit-parallel -e test pm-nitro-test-1 -- -k echo {}
CRI_ARGS=""
for i in "$@"
do
case $i in
--) shift; break;;
*) shift; CRI_ARGS="$CRI_ARGS $i";;
esac
done
# Hardcoded for now, as Centos/AWS doesn't seem to provide number of cores
# (e.g. a hack)
function prepend_cores { xargs -L1 echo 4/ ;}
HOSTS=$(mktemp /tmp/hosts.XXX)
cosmos-running-instances -c $CRI_ARGS | prepend_cores > $HOSTS
P_ARGS="--sshloginfile $HOSTS"
if [[ -t 0 ]]
then # if we don't have STDIN connected, then just run command on all hosts
P_ARGS="$P_ARGS --nonall"
fi
parallel $P_ARGS "$@" 2>/dev/null
rm $HOSTS
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment