../kde/bin/kclocknet.sh

#!/bin#
#
# This shell try to get time from the NET then call kclock.sh to set the
# new values.
#
# Parameter passed from kclock:
#
# $1 = GMT nn (where nn is from -12 to +12)
#
#
# Return Values:
#
#  0 = OK
#  1 = Wrong number of parameters (kclock.sh)
#  2 = date command failed (kclock.sh)
#  3 = clock command failed (kclock.sh)
#  4 = Wrong number of parameters
#  5 = Host not reached
#  6 = timeout getting time from the net
#

if [ $# != 2 ]
        then exit 4    #Wrong number of parameter
fi

GMT=`echo $2 | tr -d +`
dir=`dirname $0`

# start chrono
timeout=30
start=`date +%s`

#Test host
#host=localhost
#host=ftp.kde.org

# U.S. Naval Observatory Master Clock
host=tycho.usno.navy.mil

rm -f /tmp/time.net
echo -n "open $host 13" | ftp -v > /tmp/time.net

# stop chrono
stop=`date +%s`
time=`expr $stop - $start`

if [ ! -s /tmp/time.net ]
        then exit 5
fi

if [ $time -gt $timeout ]
        then exit 6
fi

var=`tail -1 /tmp/time.net`
set $var
now=$4
rm -f /tmp/time.net

MM=`date +%m`
DD=`date +%d`
YYYY=`date +%Y`
hh=`echo $now|cut -f1 -d":"`
mm=`echo $now|cut -f2 -d":"`
ss=`echo $now|cut -f3 -d":"`

# adjust UTC with local time
hh=`expr $hh + $GMT`
if [ $hh -gt 23 ]
        then hh="0"
fi
if [ $hh -lt 10 ]
        then hh="0"$hh
fi

# $1 = MM       Months  (01..12)
# $2 = DD       Day     (01..31)
# $3 = hh       Hour    (00..23)
# $4 = mm       Minute  (00..59)
# $5 = YYYY     Year    (0000..9999)
# $6 = ss       Second  (00..59)

# set time & date
echo "$dir/kclock.sh $MM $DD $hh $mm $YYYY $ss" > /tmp/kclocknet.log
$dir/kclock.sh $MM $DD $hh $mm $YYYY $ss
b=$?
exit $b


This is the shell responsible to get date & time from a remote host in the NET (by default the remote host is the  "U.S. Naval Observatory Master Clock").
The shell talk with the "daytime 13/tcp" service to get the time of the remote machine and is easily customizable to match your preferences.

Go back