bulk.sh 794 B

123456789101112131415161718192021222324252627282930313233343536
  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. ids="$(cat 'uuids.txt')"
  19. # `brew install coreutils` on OS X
  20. ids="$(shuf <<< "$ids" 2>/dev/null || gshuf <<< "$ids")"
  21. bulk() {
  22. trap return INT
  23. echo "$ids" | while read id; do
  24. if [ -z "$async" ]; then
  25. curl -sSL -o /dev/null -w "%{url_effective} %{http_code} %{time_total}s\\n" -- "$host/avatars/$id?overlay"
  26. else
  27. curl -sSL -o /dev/null -w "%{url_effective} %{http_code} %{time_total}s\\n" -- "$host/avatars/$id?overlay" &
  28. sleep "$interval"
  29. fi
  30. done
  31. }
  32. time bulk