This is kind of a follow up to this question.
My goal in the end is to use my Raspberry Pi 1 Model B to log whenever the Internet connection goes down, and for how long.
I tried doing that with the following command:
ping 8.8.8.8 | while read line; do echo "$(date): $line"; done | grep --line-buffered time= | tee -a googleping
The above command works on a Ubuntu 15.10 Server and also my MacBook Air with OS X 10.11.2. So I thought I could just use the same on the Pi. But then the first error showed up.
$ ping 8.8.8.8
ping: icmp open socket: Operation not permitted
To get around that I then started ping as super user:
$ sudo ping 8.8.8.8
PING 8.8.8.8 (8.8.8.8) 56(84) bytes of data.
64 bytes from 8.8.8.8: icmp_seq=1 ttl=58 time=12.8 ms
64 bytes from 8.8.8.8: icmp_seq=2 ttl=58 time=12.6 ms
64 bytes from 8.8.8.8: icmp_seq=3 ttl=58 time=13.0 ms
64 bytes from 8.8.8.8: icmp_seq=4 ttl=58 time=12.6 ms
--- 8.8.8.8 ping statistics ---
4 packets transmitted, 4 received, 0% packet loss, time 3004ms
rtt min/avg/max/mdev = 12.640/12.787/13.002/0.171 ms
Now you would think this solves my problem but no, after this there is another problem I noticed. The ping
command on the Pi doesn't output request timeouts. So when a package is timed out the Pi just resends it where I would expect a message like that:
Request timeout for icmp_seq 39
But what I get is just nothing, it apparently just resends the package until it gets an answer, but the lost packages show up in the summary at the end:
--- 8.8.8.8 ping statistics ---
168 packets transmitted, 131 received, 22% packet loss, time 167191ms
rtt min/avg/max/mdev = 12.082/13.099/32.888/2.322 ms
The last output before the summary is the following:
64 bytes from 8.8.8.8: icmp_seq=150 ttl=58 time=12.5 ms
Which shows that only 151 different icmp_sequences
were sent, and the dropped ones just resend over and over again.
I should also add, that I ping my local router 192.168.2.1
in addition to google 8.8.8.8
to see if it is the connection to the router, or really the connection to google.
The following results in the same output on both systems:
$ ping -V
ping utility, iputils-s20121221
After some looking around I found an option in the man page for ping on the Pi that somewhat does what I want:
$ man ping
[...]
-O Report outstanding ICMP ECHO reply before sending next packet.
This is useful together with the timestamp -D to log output to a
diagnostic file and search for missing answers.
[...]
That produces the following output if a package is too slow:
no answer yet for icmp_seq=499
But if my understanding is correct then this is different in the way that the ping
command on ubuntu only outputs the message if the answer is not received before the timeout, even if another ping package was send before the answer received. The ping
command on my Pi prints the message also out when the answer will be revived after the message is received.
So why is this different on a Pi than on a Ubuntu server? How can I achieve my goal?
Question also posted on superuser.com.
ping -V
. The Pi version may not be the same as the server one, depending on just which distribution you are using on the Pi.