Ping device or device2 and log it to a file with timestamp
I have a server, running Centos 6.2, that runs an app that is dependent on a stratus0 timeserver. I need to verify connectivity with a timeserver prior to starting NTPD and the app.
I am currently using the following cmd to accomplish this:
until /bin/ping -c 1 timeserver1 >> /var/log/ntpd.log || /bin/ping -c 1 timeserver2 >> /var/log/ntpd.log ; do
sleep 2
done
The only problem is that I cannot determine the timestamp for the log entries. I have attempted using the following cmd:
/bin/ping -c 1 timeserver1 | xargs -n1 -i bash -c 'echo `date +%F\ %T`" {}"' >> /var/log/ntpd.log || /bin/ping -c 1 timeserver2 | xargs -n1 -i bash -c 'echo `date +%F\ %T`" {}"' >> /var/log/ntpd.log ; do
sleep 2
done
The problem with this is if timserver1 is offline, it only logs the ping failure to timeserver1 and does not perform the or (||) and look for timeserver2.
If this is the wrong forum, please enlighten me and I will post it in the correct forum.
Thank you for your assistance.
|