Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/sh
- PING=/bin/ping
- COUNT=4
- DEADLINE=10
- ping_host() {
- local output=$($PING -q -c $COUNT -w $DEADLINE $1 2>&1)
- # notice $output is quoted to preserve newlines
- local temp=$(echo "$output"| /opt/bin/gawk '
- BEGIN {pl=100; rtt=0.1}
- /packets transmitted/ {
- match($0, /([0-9]+)% packet loss/, matchstr)
- pl=matchstr[1]
- }
- /^round-trip/ {
- # looking for something like 0.562/0.566/0.571/0.024
- match($0, /(.*)\/(.*)\/(.*)/, a)
- rtt=a[2]
- }
- /bad address/ {
- # no output at all means network is probably down
- pl=100
- rtt=0.1
- }
- END {print pl ":" rtt}
- ')
- RETURN_VALUE=$temp
- }
- # ping a host on the local lan
- ping_host www.google.com
- /mmc/opt/bin/rrdtool update \
- /opt/ping/stats/ping_wan.rrd \
- --template \
- pl:rtt \
- N:$RETURN_VALUE
- echo $RETURN_VALUE
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement