Skip to content

Instantly share code, notes, and snippets.

@mrsiano
Last active June 6, 2017 16:40
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 mrsiano/0a1185285f18b48a3497065df1dd76f4 to your computer and use it in GitHub Desktop.
Save mrsiano/0a1185285f18b48a3497065df1dd76f4 to your computer and use it in GitHub Desktop.
multit - run multiple system commands via pool
#! /bin/sh
# yet another simple framework to test system calls, sh scripts.
cmd=$1 # a command to run.
parallel=$2 # how many.
frequency=$3 # how often generate instance
pool=$4 # running command in certain pool size.
pool_sleep_time=$5 # how long to wait for a pool to be done.
function usage() {
echo "
USAGE:
./multit.sh <command> <parallel> <frequency> <pool> <pool_sleep_time>
"
}
function final() {
if [ $? -eq 0 ]
then
exit 0
else
echo "Opps, something went wrong, please review your call"
exit 1
fi
}
function watch_dog() {
# the following should be equivalent to -> ps -ef |grep -c '[s]leep 5'
firstchar=`echo $cmd | cut -c1`
rest=`echo $cmd | cut -c2-100`
while [ `ps -ef |grep -c "[$firstchar]$rest"` -gt 0 ]; do
sleep 1
done
}
#TODO: add statitics
[ ! -z "$cmd" ] || usage
[ ! -z "$frequency" ] || frequency=0
for p in `seq 1 $parallel`; do
nohup $cmd > /dev/null 2>&1 &
sleep $frequency
done
watch_dog
final
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment