Skip to content

Instantly share code, notes, and snippets.

@ahmetozer
Created September 26, 2020 23:00
Show Gist options
  • Save ahmetozer/5bf8f934fa90652342b343d89717919e to your computer and use it in GitHub Desktop.
Save ahmetozer/5bf8f934fa90652342b343d89717919e to your computer and use it in GitHub Desktop.
Update time with date and curl commands from cloudflare
#!/bin/sh
# Update time and date from cloudflare with curl and date commands.
# It is easy to use ntp is not installed servers.
# You can execute for one time update or execute with service arg to update every 600 second.
function updateDate {
date -s"@$(curl ahmetozer.org/cdn-cgi/tracert -s | grep ts= | cut -d"=" -f2 | cut -d"." -f1)"
if [ "$?" == "0" ]
then
updated="true"
fi
}
if [ "$1" == "service" ] || [ "true" == "$service" ]
then
while true
do
updateDate
if [ "$updated" == "true" ]
then
sleep 600
else
sleep 30
fi
done
else
updateDate
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment