bulk.sh 831 B

12345678910111213141516171819202122232425262728293031323334353637
  1. #!/usr/bin/env bash
  2. async="true"
  3. interval="0.1"
  4. if [ "$1" = "-s" ]; then
  5. async=""
  6. shift
  7. elif [ "$1" = "-i" ]; then
  8. interval="$2"
  9. shift 2
  10. fi
  11. host="$1"
  12. shift
  13. if [ -z "$host" ] || [ ! -z "$@" ]; then
  14. echo "Usage: $0 [-s | -i <interval>] <host uri>"
  15. exit 1
  16. fi
  17. # insert newline after uuids
  18. id_file="$(echo | cat 'uuids.txt' - 'usernames.txt')"
  19. # `brew install coreutils` on OS X
  20. id_file="$(shuf <<< "$id_file" || gshuf <<< "$id_file")"
  21. mapfile ids <<< "$id_file"
  22. bulk() {
  23. trap return INT
  24. for id in $ids; do
  25. if [ -z "$async" ]; then
  26. curl -sSL -o /dev/null -w "%{url_effective} %{http_code} %{time_total}s\\n" -- "$host/avatars/$id?helm"
  27. else
  28. curl -sSL -o /dev/null -w "%{url_effective} %{http_code} %{time_total}s\\n" -- "$host/avatars/$id?helm" &
  29. sleep "$interval"
  30. fi
  31. done
  32. }
  33. time bulk