sufehmi

pingmon.sh

Feb 8th, 2022
1,643
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 1.14 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. # pingmon.sh
  4. #
  5. # will enable you to not just monitor availability of a network target, but also
  6. # its network (ping) performance
  7. #
  8. # using this guide, I was able to keep a Google Sheet up-to-date automatically:
  9. # https://academy.datawrapper.de/article/288-how-to-set-up-automatic-updates-on-a-google-sheet
  10. #
  11. # then I use that google sheet as the datasource for a Google Data Studio dashboard, see here:
  12. # https://datastudio.google.com/reporting/95d8823c-2c9c-4a09-beee-4004207025e2
  13. #
  14.  
  15. target=10.10.22.1
  16. logfile=/root/scripts/pingmon.log
  17.  
  18. today=$(date '+%Y-%m-%d')
  19. currtime=$(date '+%H:%M:%S')
  20.  
  21. msg=`ping -c 1 $target`
  22.  
  23. # if ping successful, then find out the result
  24. #if [[ "$msg" =~ "100% packet loss" ]] ; then
  25. if echo $msg | grep -q "100% packet loss" ; then
  26.  
  27.     # device is unreachable
  28.     # set speed to zero
  29.     speed=0
  30.    
  31. else
  32.  
  33.     # get the milisecond number
  34.     speed=`echo $msg | grep icmp_seq | cut -d "=" -f 4 | cut -d " " -f 1`
  35.  
  36. fi
  37.  
  38. # write to log in CSV format
  39. echo $today,$currtime,$speed >> $logfile
  40.  
  41. exit
  42.  
  43. # just for debugging
  44. #if echo $msg | grep -q "100% packet loss" ; then echo LOSS ; else echo FINE ; fi
  45.  
Advertisement
Add Comment
Please, Sign In to add comment