bulk.sh 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. #!/usr/bin/env bash
  2. hostname="crafatar.com"
  3. async="true"
  4. random="false"
  5. interval="0.1"
  6. usage() {
  7. echo "Usage: $0 [-s | -r | -i <interval> | -h <hostname>]... <host uri>" >&2
  8. exit 1
  9. }
  10. get_ids() {
  11. local shuf
  12. if [ "$random" = "true" ]; then
  13. while true; do uuid -v 4; done
  14. else
  15. # `brew install coreutils` on OS X for gshuf
  16. shuf=$(command -v shuf gshuf)
  17. # randomize ids
  18. $shuf < uuids.txt
  19. fi
  20. }
  21. bulk() {
  22. trap return INT # return from this function on Ctrl+C
  23. get_ids | while read id; do
  24. if [ "$async" = "false" ]; then
  25. curl -H "Host: $hostname" -sSL -o /dev/null -w "%{url_effective} %{http_code} %{time_total}s\\n" -- "$host/avatars/$id?overlay"
  26. else
  27. curl -H "Host: $hostname" -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. while [ $# != 0 ]; do
  33. case "$1" in
  34. -s)
  35. async="false";;
  36. -r)
  37. random="true";;
  38. -i)
  39. interval="$2"
  40. shift;;
  41. *)
  42. [ -n "$host" ] && usage
  43. host="$1";;
  44. esac
  45. shift
  46. done
  47. [ -z "$host" ] && usage
  48. time bulk