time correction with perl & ntpdate
Friday, April 30, 2010 10:27:11 AM
#!/usr/bin/perl
$timeserver="time.stdtime.gov.tw";
# get localtime via perl function
($sec,$min,$hour,$day,$mon,$year)=localtime(time);
$mon++;
if (length ($mon) == 1) {$mon = '0'.$mon;}
if (length ($day) == 1) {$day = '0'.$day;}
$year+=1900;
# get localtime via NTP
$time=`ntpdate -q $timeserver | sed '1d' | cut -d " " -f3` or die "Aborted";
($hour1,$min1,$sec1) = split(/:/,$time);
if (length ($hour1) == 1) {$hour1 = '0'.$hour1;}
if (length ($min1) == 1) {$min1 = '0'.$min1;}
if (length ($sec1) == 1) {$sec1 = '0'.$sec1;}
# time correction
$alltime="$mon$day$hour1$min1$year.$sec1";
print $alltime;
#system(date $alltime);
$timeserver="time.stdtime.gov.tw";
# get localtime via perl function
($sec,$min,$hour,$day,$mon,$year)=localtime(time);
$mon++;
if (length ($mon) == 1) {$mon = '0'.$mon;}
if (length ($day) == 1) {$day = '0'.$day;}
$year+=1900;
# get localtime via NTP
$time=`ntpdate -q $timeserver | sed '1d' | cut -d " " -f3` or die "Aborted";
($hour1,$min1,$sec1) = split(/:/,$time);
if (length ($hour1) == 1) {$hour1 = '0'.$hour1;}
if (length ($min1) == 1) {$min1 = '0'.$min1;}
if (length ($sec1) == 1) {$sec1 = '0'.$sec1;}
# time correction
$alltime="$mon$day$hour1$min1$year.$sec1";
print $alltime;
#system(date $alltime);






