Ping server every second to see uptime Ping server every second to see uptime shell shell

Ping server every second to see uptime


while true; do ping -c 1 server | do stuff w/ output;sleep 1;done

To qualify for the "edit (may reboot)" just create an init-script thatstarts the loop again.


I know you asked about ping. There are other things to consider as well.

A more reasonable way to get "uptime" is to use the something that queries a database like wtpmx, utmp, or other files meant for this. The ping protocol, ICMP can be and will be ignored by a busy system. A missed return does not always mean the system is down. Or the system is not working.There can be a lot of reasons.

One way to consider getting uptime on a modern UNIX box:

ssh remoteserver 'uptime'

Also consider "why" you are pinging.

Ping is useful to check if a system is alive and responds to ping packets,, but may not tell you if a system is actually functioning. This is probably what you want to know for sure. For example, a database server or mailserver may have some hung processes. So it responds to ping but does very little of what it is intended to do. You may want to construct a more useful command than just ping. We log into a 24x7 prod database on a server once per minute and have it run a sql script that echoes something harmless like 'OKAY'. e.g.,

select 'OKAY' from dual;


You can write a cronjob to achieve this with the help of the following script.

1 * * * * /bin/ping -c2 www.google.com | while read pong; do echo "$(date): $pong"; done >> ~/pings/google.com.log

It pings google.com every 1 min & logs the output with current date & time to the file path.