Advertisement
Guest User

Untitled

a guest
Aug 26th, 2013
128
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 0.75 KB | None | 0 0
  1. #!/bin/sh
  2.  
  3. PING=/bin/ping
  4. COUNT=4
  5. DEADLINE=10
  6. ping_host() {
  7. local output=$($PING -q -c $COUNT -w $DEADLINE $1 2>&1)
  8. # notice $output is quoted to preserve newlines
  9. local temp=$(echo "$output"| /opt/bin/gawk '
  10. BEGIN {pl=100; rtt=0.1}
  11. /packets transmitted/ {
  12. match($0, /([0-9]+)% packet loss/, matchstr)
  13. pl=matchstr[1]
  14. }
  15. /^round-trip/ {
  16. # looking for something like 0.562/0.566/0.571/0.024
  17. match($0, /(.*)\/(.*)\/(.*)/, a)
  18. rtt=a[2]
  19. }
  20. /bad address/ {
  21. # no output at all means network is probably down
  22. pl=100
  23. rtt=0.1
  24. }
  25. END {print pl ":" rtt}
  26. ')
  27. RETURN_VALUE=$temp
  28. }
  29. # ping a host on the local lan
  30. ping_host www.google.com
  31.  
  32. /mmc/opt/bin/rrdtool update \
  33. /opt/ping/stats/ping_wan.rrd \
  34. --template \
  35. pl:rtt \
  36. N:$RETURN_VALUE
  37. echo $RETURN_VALUE
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement