Last active
May 12, 2020 11:08
-
-
Save sony-mathew/f8dd3fc1f9ec9b389849e57c2c93dacf to your computer and use it in GitHub Desktop.
Run commands arbitrary number of times. (Use-cases : test out flakey failures, test out external system performance etc)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# eg : ./spec_runner.sh -n 2 -c "ls -l" | |
# -n => number of times | |
# -c => command to be run | |
repeats=5 | |
command_to_run="echo Hello World" | |
line_break() { | |
echo "-------------------------------------------------------------------" | |
} | |
loop_run_command() { | |
echo "Running command \"$command_to_run\" for $repeats times" | |
line_break | |
for (( i = 1; i <= $repeats ; i++ )) | |
do | |
line_break | |
echo "Current Run : $i" | |
line_break | |
eval "$command_to_run" | |
done; | |
} | |
while getopts n:c: OPT | |
do | |
case "$OPT" in | |
n) | |
repeats=$OPTARG | |
;; | |
c) | |
command_to_run=$OPTARG | |
;; | |
\?) | |
echo 'No arguments supplied. Running default command.' | |
;; | |
esac | |
done | |
loop_run_command | |
line_break | |
echo "Done.✅" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment