I want to find a Terminal command that will provide a timestamped ping every second for a period of time (say 5 minutes) and then pause for another period of time (say 30 minutes) and then repeat that process until I stop it. I will need to let it run for days.
In other words, what I want is sort of a combination of the following 2:
1) ping 8.8.8.8 | while read line; do echo `date` - $line; done
2) ping 8.8.8.8 | while read line; do echo `date` - $line; sleep 1800; done
(1) provides a ping listing every second with a timestamp, while (2) does the same thing but every 30 minutes instead of every second. I can use (1) but it generates way more data than I need. (2) provides the pauses I need but cannot catch the events I'm looking for (which last about 4 seconds, see below).
Although not needed to answer my question, the reason I want this is to deal with an intermittent internet connectivity problem. By using (1) above I have found that most of the time my internet connection is fine, but every couple of days or so there will be periods (lasting hours) during which I get unusually high pings for about 4 seconds, and this repeats every 15 seconds or so. But using (1) to figure that out meant a lot of unnecessary data collection. Also, I have a separate script which will plot the data and there are just way too many data points to plot conveniently since I need to collect for days.
I'm running OS 13.2 on a MacAir M1
Best Answer
--apple-time
obviously is an Apple addition which is quite useful for what you need here, the output would look likeIf you just want the timestamp and the ping time, you can use
sed
to filter out the noise:To accomplish the same without relying on Apple-specific options, you can also just take your second command and put the
sleep
outside of thewhile read line
loop:or, again without the noise