On our macOs virtual machine, that we use for building, the time sometimes jumps out of no reason. As a workaround I have created this script named test.sh
that consistently corrects the time:
#!/bin/bash -e
while true; do
sudo ntpdate -u de.pool.ntp.org >> ntpdate.txt; sleep 30;
done
At the beginning of a build this gets started in the background:
./test.sh &
When the build is finished I'm killing it:
kill $(ps aux | grep test.sh | grep -v grep | awk '{print $2}')
Sometimes the call to update the time takes longer than 30 seconds. Then there are two open calls to the ntp pool and I'm getting a rate limit response. Therefore I want to limit the calls to ntp to only one at a time. How do I achieve this in my while true loop?