Advertisement
sergio_educacionit

ping_monintor-v1.sh

Jan 13th, 2024
1,237
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 0.98 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3.  
  4. # medidor de ping
  5. # https://espanol.cox.com/residential/internet/guides/gaming-performance/ping-testing.html}
  6.  
  7. # Menos de 50 ms 'bueno'
  8. # Menos de 100 ms 'regular'
  9. # Menos de 150 ms 'malo'
  10. # Mayor a 150 ms 'sin conexion'
  11.  
  12. # 1 True
  13. # 0 False
  14.  
  15. host=$1
  16.  
  17. while :; do
  18.  
  19.     clear
  20.  
  21.     ping=$(ping -c 1 $host | grep "64 bytes from" | cut -d "=" -f 4 | cut -d " " -f 1)
  22.  
  23.  
  24.     # si el valor es entero pasarlo a decimal.
  25.  
  26.     [[ "$ping" =~ .*$ ]] || ping=${ping}.0
  27.  
  28.  
  29.     if [ $(awk 'BEGIN { if ('$ping' > 100.0) print 1; else print 0 }') -eq 1 ] &&  
  30.         [ $(awk 'BEGIN { if ('$ping' <= 150.0) print 1; else print 0 }') -eq 1 ]; then
  31.  
  32.         echo "malo"
  33.  
  34.     elif [ $(awk 'BEGIN { if ('$ping' <= 50.0) print 1; else print 0 }') -eq 1 ]; then
  35.  
  36.         echo "bueno"
  37.  
  38.     elif [ $(awk 'BEGIN { if ('$ping' > 150.0) print 1; else print 0 }') -eq 1 ]; then
  39.  
  40.         echo "sin conexion"
  41.  
  42.     else
  43.         echo "regular"
  44.  
  45.     fi
  46.  
  47.     sleep 0.5
  48. done
  49.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement