[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[debian-users:26577] Re: adjtimex で時間調整
佐野@浜松です。
on "Wed, 24 Jan 2001 02:25:24 +0900', I wrote:
> -- timeadjust.pl --
すみません、一度動かした後でまた変更していたのに、動作チェック
してませんでした。今朝やってみたら動かなかったのでミスに
気がつきました ^^;;
更新した版を流しておきます。
# sh script で書き直して BTS に送ったら adjtimex パッケージに
# 含めてもらえないかな ?
-- timeadjust.pl (2nd version) --
#! /usr/bin/perl
require 5.004;
use strict;
use IO::File;
my $ADJTIMEX = "/sbin/adjtimex";
my $GREP = "/bin/grep";
my $DATE = "/bin/date";
my $AT = "/usr/bin/at";
main();
sub main() {
my $ADJ;
my $RESET;
my $TICK;
my $TIMEX;
my $TIMEXP;
my $ATCOM;
my $fh = new IO::File;
if (!defined $ARGV[0]) {
print "usage: timeadjust.pl adjust_minutes\n";
print " if adjust_minutes is positive, ";
print "then clock will speed up.\n";
print " if adjust_minutes is negative, ";
print "then clock will slow down.\n";
exit 1;
}
$ADJ = getnum($ARGV[0]);
if (!defined $ADJ) {
print " Please set numeric argument\n";
print " Invalid argument [" . $ARGV[0] . "]\n";
exit 1;
}
$RESET = $ADJ * 10;
if ($ADJ < 0) {
$TICK = 9000;
$RESET = abs $RESET;
} else {
$TICK = 11000;
}
$TIMEX = $ADJTIMEX . " --tick " . $TICK;
$TIMEXP = $ADJTIMEX . " -p|" . $GREP . " tick";
printf "use \"%s\" ", $TIMEX;
$ATCOM = $AT . " now + " . $RESET . " minutes";
printf "and \"%s\" ", $ATCOM . "\n";
print " with \"/etc/init.d/adjtimex start\"\n";
system($TIMEXP);
system($TIMEX);
system($TIMEXP);
$fh = new IO::File "|$ATCOM";
print $fh $TIMEXP . "\n";
print $fh "/etc/init.d/adjtimex start\n";
print $fh $DATE . "\n";
print $fh $TIMEXP . "\n";
$fh->close;
exit 0;
}
sub getnum($) {
use POSIX qw(strtod);
my ($str) = @_;
$str =~ s/^\s+//;
$str =~ s/\s+$//;
$! = 0;
my($num, $unparsed) = strtod($str);
if (($str eq '') || ($unparsed != 0) || $!) {
return undef;
} else {
return $num;
}
}
--
# (わたしのおうちは浜松市、「夜のお菓子」で有名さ。)
<kgh12351@xxxxxxxxxxx> : Taketoshi Sano (佐野 武俊)