Quantcast
Viewing all articles
Browse latest Browse all 102

How to get the average ping time?

Here's a real result of my ping 192.168.1.1 command:

64 bytes from 192.168.1.1: icmp_seq=964 ttl=64 time=1018 ms64 bytes from 192.168.1.1: icmp_seq=965 ttl=64 time=921 ms64 bytes from 192.168.1.1: icmp_seq=966 ttl=64 time=847 ms64 bytes from 192.168.1.1: icmp_seq=967 ttl=64 time=866 ms64 bytes from 192.168.1.1: icmp_seq=968 ttl=64 time=895 ms64 bytes from 192.168.1.1: icmp_seq=969 ttl=64 time=858 ms64 bytes from 192.168.1.1: icmp_seq=970 ttl=64 time=886 ms64 bytes from 192.168.1.1: icmp_seq=971 ttl=64 time=890 ms64 bytes from 192.168.1.1: icmp_seq=972 ttl=64 time=888 ms64 bytes from 192.168.1.1: icmp_seq=973 ttl=64 time=910 ms64 bytes from 192.168.1.1: icmp_seq=974 ttl=64 time=915 ms64 bytes from 192.168.1.1: icmp_seq=975 ttl=64 time=937 ms64 bytes from 192.168.1.1: icmp_seq=976 ttl=64 time=933 ms64 bytes from 192.168.1.1: icmp_seq=977 ttl=64 time=947 msping: sendmsg: Network is unreachableping: sendmsg: Network is unreachableping: sendmsg: Network is unreachableping: sendmsg: Network is unreachableping: sendmsg: Network is unreachableping: sendmsg: Network is unreachable64 bytes from 192.168.1.1: icmp_seq=985 ttl=64 time=1.09 ms64 bytes from 192.168.1.1: icmp_seq=986 ttl=64 time=2.02 ms64 bytes from 192.168.1.1: icmp_seq=987 ttl=64 time=3.37 ms64 bytes from 192.168.1.1: icmp_seq=988 ttl=64 time=1.08 ms64 bytes from 192.168.1.1: icmp_seq=989 ttl=64 time=2.87 ms64 bytes from 192.168.1.1: icmp_seq=990 ttl=64 time=1.11 ms64 bytes from 192.168.1.1: icmp_seq=991 ttl=64 time=1.39 ms64 bytes from 192.168.1.1: icmp_seq=992 ttl=64 time=1.11 ms64 bytes from 192.168.1.1: icmp_seq=993 ttl=64 time=1.10 ms

For some unknown reasons, sometimes my WiFi connection gets very slow and the main cause is the ping time.

I should manually disconnect my WiFi and reconnect it.

I'm on Ubuntu 20.04 LTS.

I want to make it automatic. Here are the script snippets I came up with. But I can't put them together:

# Read time using awkping 192.168.1.1 | awk '{gsub("time=", ""); print $7}'# Disconnecting from WiFinmcli con down WiFiName# Reconnecting to WiFinmcli device wifi connect

I tried this, but it does not work:

while read Line; do    echo "read line"    echo $Linedone <<< $(ping 192.168.1.1)

Basically, I'm stuck at redirecting ping standard output to a while loop, and I'm stuck at aggregating the average time using the awk command.

How can I combine them together?

Update

For anyone interested in the final script, please see my answer below.


Viewing all articles
Browse latest Browse all 102

Trending Articles