Last active
August 29, 2015 14:09
-
-
Save tiagofaustino/898c145a3730468a0e4d to your computer and use it in GitHub Desktop.
Forma alternativa de atualizar a hora por wget quando o NTPD é bloqueado no servidor
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/bash | |
AGORA_XML=$(wget -qO- "http://api.timezonedb.com/?zone=America/Sao_Paulo&key=<SUA-KEY-API>") | |
AGORA_XML_STATUS=$(grep -oPm1 "(?<=<status>)[^<]+" <<< "$AGORA_XML") | |
# Script de atualização de data por API externa do site timezonedb.com | |
# | |
#Se o site estiver fora do ar deverá terminar o processo | |
if [ "$AGORA_XML_STATUS" != "OK" ]; then | |
echo "Houve um erro ao fazer update da data" | |
exit 1 | |
else | |
#Coleta o timestamp do XML | |
TIMESTAMP_TEMP=$(grep -oPm1 "(?<=<timestamp>)[^<]+" <<< "$AGORA_XML") | |
#Coleta o GMT offset do XML | |
GMTOFFSET=$(grep -oPm1 "(?<=<gmtOffset>)[^<]+" <<< "$AGORA_XML" | sed 's|[^0-9]||g') | |
#Deve-se somar o timestamp com o GMT offset | |
TIMESTAMP=$((TIMESTAMP_TEMP+GMTOFFSET)) | |
#seta a data | |
date +%s -s @$TIMESTAMP | |
echo -n "Data atualizada para: " | |
date -d @$TIMESTAMP | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment