I have found the nice script below to ping a host to check if it is up or down. However I haven't found a way (and my very basic programming knowledge has failed me here) on how I can ping multiple servers. Ideally I'd go HOST1= XXX, HOST2=YYY etc...

Could someone point me in the right direction? I have about 10 hosts I'd like to see the up/down status for. Geektool script copied from macosxtips.co.uk

PING=`ping -q -c 1 $HOST`
if [[ $? -eq 0 ]] ; then
    TIME=`echo $PING |tail -1 | cut -d/ -f 5`
    echo ${TIME}ms away from $HOST
    exit 0
    echo $HOST could not be reached
    exit 2

You want to read up on loops in bash scripts.

For example:


for machine in $HOSTS
  PING=`ping -q -c 1 $machine`
  if [[ $? -eq 0 ]] ; then
    TIME=`echo $PING |tail -1 | cut -d/ -f 5`
    echo ${TIME}ms away from $machine
    echo $machine could not be reached

I didn't test that, but it's close enough. Replace the HOSTS list with the list of hosts you want to report on.


To ping multiple hosts with the red/green feedback image you need to run multiple instances of the ping geeklet. Just open ping.glet multiple times, enter a different host name each time and line them up on your screen to get the effect seen in the screenshot at the site you linked.

You can rewrite the script to ping multiple sites but you'll only get one red/green feedback image.

  • Thanks, yep just figured that one out. Appreciate the feedback :) – pknz Aug 5 '14 at 0:06

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .