Skip to content

Instantly share code, notes, and snippets.

@base698
Created August 22, 2016 22:08
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 base698/8002cfdfd5eb887d6e7fd461756779c2 to your computer and use it in GitHub Desktop.
Save base698/8002cfdfd5eb887d6e7fd461756779c2 to your computer and use it in GitHub Desktop.
Create a bunch of random users for a PG Database
#!/bin/bash
psql < create.sql
shuffled=./shuffled-words.txt
cat /usr/share/dict/words | awk 'BEGIN{srand()}{printf "%06d %s\n", rand()*1000000, $0;}' | sort -n | cut -c8- | head -n 20000 > $shuffled
>inserts.sql
exec 5< $shuffled
while read line1 <&5 ; do
read line2 <&5
first_name=$line1
last_name=$line2
city_id=$(((RANDOM<<15)|RANDOM))
gender=$(( ( RANDOM % 2 ) + 1 ))
echo "insert into users (first_name, last_name, email, gender, city_id, password) VALUES ('$first_name', '$last_name', '$first_name.$last_name@gmail.com', '$gender', $city_id, '$(echo $first_name $last_name | md5)');" >> ./inserts.sql
done
psql < ./inserts.sql
seq 1 $(wc -l ./inserts.sql | egrep -o "[0-9]+") | while read line
do
echo "http://localhost:3000/users/$line"
done | awk 'BEGIN{srand()}{printf "%06d %s\n", rand()*1000000, $0;}' | sort -n | cut -c8- > siege.conf
rm ./inserts.sql
rm $shuffled
exec 5<&-
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment