Pinging specific hosts multiple times and with nice data output in zsh

I constantly use ping to verify how’s my connection doing. Today I got sick from these prompts, because I’m used to seeing a piece (usually the beginning) of the terminal window, and the “useful” information with this output is at the end. So, in most of the cases I see this picture (you can see how annoying it is):

So, I decided to find another way. A quick search led me to the article “How can I format the output of ping in bash?” which I used to create the ping.sh script that I’m using from now on.

Of course, I would have gone nowhere without ChatGPT. My scripting skills are quite basic, so I decided to use ChatGPT for help. Starting with the initial code above, but with the help of “the still good transformer,” I finally have a ping.sh, which outputs what I needed. It has the following benefits:

  1. It outputs the result first thing in the row, with the data that I care about, so I can keep it squeezed somewhere on the screen without the need for a bigger real estate:
  2. It can quit on a key press. This required zsh for MacOS, but I’m OK with this limitation.
  3. I can add more hosts if I need it (the default script had this possibility, so I inherited it). This also revealed a bug: for some reason when there was more than one hostname, it didn’t work with the initial list (as a string). I had to do it the “zsh way”.

Conclusion: ChatGPT rules (and really helps), and I finally have my ping in the way I always wanted.

Leave a Reply

Theme: Overlay by Kaira Extra Text