Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.