Last active
May 30, 2018 16:10
-
-
Save eiri/3d6e47b704b6b65f55474c0ada208db2 to your computer and use it in GitHub Desktop.
Bash script to generate random json objects. (Mac version)
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 | |
# prereq `brew install coreutils jo` | |
defcount=1 | |
display_usage() { | |
echo -e "Generate NUMBER of random json objects." | |
printf " Usage: %s [NUMBER] (DEFAULT: %s)\n\n" $(basename "$0") $defcount | |
} | |
random_number() { | |
gshuf -i 1-$1 -n 1 | |
} | |
random_hex () { | |
openssl rand -hex $1 | |
} | |
randon_uuid() { | |
uuidgen | tr '[:upper:]' '[:lower:]' | |
} | |
random_string () { | |
base64 /dev/urandom | tr -d '\+\/' | dd bs=$1 count=1 2>/dev/null | |
} | |
random_boolean() { | |
gshuf -i 0-1 -n 1 | |
} | |
random_word() { | |
gshuf -n 1 /usr/share/dict/words | tr -d '\n' | |
} | |
random_name() { | |
gshuf -n 1 /usr/share/dict/propernames | tr -d '\n' | |
} | |
if [[ ( $@ == "--help") || $@ == "-h" ]] | |
then | |
display_usage | |
exit 0 | |
fi | |
for i in $(seq ${1:-$defcount}) | |
do | |
printf -v count2 "%04d" $i | |
jo \ | |
seq=$i \ | |
-s count=$(printf "%04d" $i) \ | |
number=$(random_number 1000) \ | |
string=$(random_string 16) \ | |
hex=$(random_hex 16) \ | |
uuid=$(randon_uuid) \ | |
bool@$(random_boolean) \ | |
word=$(random_word) \ | |
name=$(random_name) | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment