Created
April 17, 2021 02:47
-
-
Save WR4F/50859d2f1521ad7013ce1503b025c57a to your computer and use it in GitHub Desktop.
Script to set datetime localtime $TZ Variable
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
# Adjust the number 2 to suit your needs, or use a different timezone like PDT | |
export TZ=EST2EDT | |
# Get the current time from an internet site (clearly, not a reliable method) and store into file | |
wget "https://www.utctime.net/" -O curtime.txt && grep "td>UTC</td" curtime.txt|head -n 1|cut -f 4 -d '>'|cut -f 1 -d '<'|sed -e 's/T/ /g'| | |
# Remove the Z character (for me, on a weird Unix distro, this causes the date command issues) | |
sed -e 's/Z//g' > curtime_fmt.txt && | |
# Take a few seconds, just in case, because some versions of wget theoretically(?) might not be blocking | |
sleep 3 && | |
# Set time value from file | |
date -s "$(cat curtime_fmt.txt)" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment