| Category: | Date/Time |
| Author/Contact Info | PearlJamned |
| Description: | A simple enough, yet effecient perl script which uses a list defined as @serverlist to set a *nix system's time...also added for loop which verifies the time server so that dead servers are bypassed! Change it or do whatever you want with it, but PLEASE - gimme some feedback...thx |
#!/usr/bin/perl
#
#timeset.pl ver2.0 final
#
#A simple enough, yet effecient perl script which
#uses a list defined as @serverlist to set a *nix
#system's time...also added for loop which verifies
#the time server so that dead servers are bypassed
#if none of these servers work chk yo connection ;)
#PLEASE - gimme some feedback...thx
#
################################################
#Charlie Collins (ccollins@pharmacore.com) #
#warning: beware of the penguin...AWK! #
#perlmonks.org -=PearlJamned=- #
#yadda, yadda, yadda #
#hope this helps someone #
#I'm a perl newB so lemme know what I coulda #
#done better, plz #
################################################
$synchlists = "rdate -s";
@synchtimeh = ("hwclock", "--hctosys");
@synchtimei = ("hwclock", "--systohc");
@serverlist = ("time.nist.gov",
"ntp.cmr.gov",
"tock.usno.navy.mil",
"tick.usno.navy.mil",
"time.twc.weather.com",
"tick.mit.edu",
"ntp.colby.edu");
$list = @serverlist;
for ($count = 1; $count <= $list;) {
$ping = @serverlist[$count-1];
@number[$count-1] = `ping -q -c 1 $ping`;
print "$count: \n" ;
print "@number[count-1] \n";
if (@number[$count-1] eq "") {
print "\n$ping was not found\n";
$count++
}
else {
$count = $list+1; #breaks loop
}
}
@synchtimes = ($synchlists, $ping);
system(@synchtimes);
system(@synchtimei);
system(@synchtimeh);
#feedback please <ccollins@pharmacore.com>
#the time server I've chosen to use (unless it dies)
#time.nist.gov
#hwclock --systohc --hctosys
#rdate -s time.nist.gov
#serverlist from
http://www.eecis.udel.edu/~mills/ntp/servers.htm
#other info
http://www.bgw.org/tutorials/operating_systems/linux/set_c
ock.php3
|
|
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: TimeSet.pl
by jdavidboyd (Friar) on Jul 16, 2002 at 17:01 UTC | |
by PearlJamned (Initiate) on Jul 16, 2002 at 17:50 UTC | |
by hossman (Prior) on Jul 16, 2002 at 18:46 UTC | |
by seanbo (Chaplain) on Jul 17, 2002 at 17:15 UTC | |
by Anonymous Monk on Jul 24, 2002 at 19:08 UTC |