scripts

unixus scriptus
git clone https://s.sonu.ch/~roket1428/scripts.git
Log | Files | Refs

clockfix (572B)


      1 #!/bin/sh
      2 
      3 # time and date fixer
      4 
      5 # visit worldtimeapi.org and change this link according to your location.
      6 
      7 # check root access
      8 { [ "$(whoami)" != "root" ] && echo "You must be a root user." >&2; } && exit 1
      9 
     10 # change this
     11 curl -so /tmp/datetime http://worldtimeapi.org/api/timezone/Continent/City.txt
     12 
     13 lcdatetime=$(date +%Y%m%d%T)
     14 nwtime=$(< /tmp/datetime sed -E 's/^.*T//g;3!d;s/\..*//')
     15 nwdate=$(< /tmp/datetime sed -E 's/T.*//g;3!d;s/^.*\ //;s/-//g')
     16 
     17 if [ "$lcdatetime" != "${nwdate}${nwtime}" ]
     18 then
     19 	date +%Y%m%d -s "$nwdate"
     20 	date +%T -s "$nwtime"
     21 	hwclock -w
     22 fi