How to ping a network host at regular intervals

ping

I am trying to debug WiFi connectivity issues on my home network. I have a Macbook and a Linux desktop client. I would like to run ping on both machines and compare their results. I am comfortable with Linux, this question is exclusively about the Macbook.

$ ping 192.168.0.1 | while read pong; do echo "[$(date +%s)] $pong"; done
...
[1596203814] 64 bytes from 192.168.1.254: icmp_seq=8900 ttl=64 time=9.800 ms
[1596203815] 64 bytes from 192.168.1.254: icmp_seq=8901 ttl=64 time=5.546 ms
[1596205241] Request timeout for icmp_seq 8902
[1596205241] 64 bytes from 192.168.1.254: icmp_seq=8903 ttl=64 time=26.988 ms
[1596205242] 64 bytes from 192.168.1.254: icmp_seq=8904 ttl=64 time=4.397 ms
...

As you can see from the timestamps there is a 20+ minutes gap at some point. I let the setup run for 3 hours and this happened on 5 different occasions. The Macbook was locked with Amphetamine running, the lid was closed but an external display was connected through a USB-C hub with HDMI output. I do not believe the Macbook can go to sleep under these circumstances.

Would anyone please know how I can fix my setup to ping at regular intervals, without any large gap?

Best Answer

The Macbook was locked with Amphetamine running, the lid was closed but an external display was connected through a USB-C hub with HDMI output. I do not believe the Macbook can go to sleep under these circumstances.

I wouldn't be so sure. Just check the output of pmset -g log | grep "Display is turned off" - if it happened when the ping got interrupted, you Mac went to sleep. I find Macbooks particularly stubborn when the charger is disconnected. Also note that if the external display was turned off, or switched to another input, this can also be sometimes detected (depends on model/connection, I assume), so this could also trigger the sleep.

There's no magic switch to ping to issue echo requests regularly - it does that by default.