Created
September 26, 2020 23:00
-
-
Save ahmetozer/5bf8f934fa90652342b343d89717919e to your computer and use it in GitHub Desktop.
Update time with date and curl commands from cloudflare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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