rsping.sh 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. #!/bin/bash
  2. cflag=
  3. kflag=5
  4. nflag=5
  5. pflag=15
  6. rflag=
  7. while getopts ck:n:p:r name
  8. do
  9. case $name in
  10. c) cflag=1;;
  11. k) if [ ! -z "$OPTARG" ]; then kflag="$OPTARG"; fi;;
  12. n) if [ ! -z "$OPTARG" ]; then nflag="$OPTARG"; fi;;
  13. p) if [ ! -z "$OPTARG" ]; then pflag="$OPTARG"; fi;;
  14. r) rflag="-r";;
  15. ?) printf "Usage: %s [-c] [-k value] [-n value] -r\n\t-c to use previous results\n\t-k to specify sort field (default 5)\n\t-n to specify how many lines to show (default 5)\n\t-p number of pings to send (default 15)\n\t-r to sort in reverse\n" $0
  16. exit 1;;
  17. esac
  18. done
  19. if [ ! -z "%cflag" ] && [ ! -e runescape.pings ]
  20. then
  21. echo "No previous run file, deactivating -c"
  22. cflag=
  23. fi
  24. if [ ! -z "$cflag" ]
  25. then
  26. echo "Using previous values"
  27. else
  28. echo -n "" > runescape.pings
  29. echo "Gathering pings...";
  30. for i in {1..139}
  31. do
  32. # world received lost min avg max mdev
  33. (ping -c $pflag -i 0.2 world$i.runescape.com |tail -n2 |sed -r '{N;s#.* ([0-9]+) received, ([0-9]+)% packet loss.*= ([0-9.]+)/([0-9.]+)/([0-9.]+)/([0-9.]+) ms.*# '$i' \1 \2 \3 \4 \5 \6 #g}' >> runescape.pings; echo -n . )&
  34. done
  35. wait
  36. fi
  37. echo -e "\nSorting..."
  38. echo " _______________________________________________________________ "
  39. echo -e "|\t|\t Pings\t|\t Times (ms)\t\t|"
  40. echo -e "| World\t| Received\t| Lost%\t| Min\t| Avg\t| Max\t| Mdev\t|"
  41. echo "|-------|---------------|-------|-------|-------|-------|-------|"
  42. sort -k $kflag -n $rflag runescape.pings | head -n $nflag | sed -r '{
  43. s/([0-9]{3}\.[0-9])[0-9]* /\1 /g;
  44. s/([0-9]{2}\.[0-9]{2})[0-9]* /\1 /g;s/ / /g;
  45. s/ (.) / _____\1_ /g ;
  46. s/ (..) / ____\1_ /g ;
  47. s/ (...) / ___\1_ /g ;
  48. s/ (....) / __\1_ /g ;
  49. s/ (.....) / _\1_ /g ;
  50. s/ (......) / \1_ /g ;
  51. s/ (.......) / \1 /g ;
  52. s/ /|/g;
  53. s/_/ /g;
  54. s/^(\| *[0-9]+ )\|( *[0-9]+ \| *[0-9]+ )\|/\1|\t \2|/g
  55. }'
  56. echo "'-------'---------------'-------'-------'-------'-------'-------'"