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
$synchlists = "rdate -s"; --> its in @synchtimes = ($synchlists, $ping); {near bottom} --> for some reason I had to save it as a scalar value
to get the system to run it like it should...at least
I believe that was the problem, I had to jump through
a few hoops to get this baby working...cc
I believe hte question was not about the variable,
but about the acctually program "rdate" that you
execute.
The poster points out that it doesn't exist on his
Mandrake or Cygwin systems, ...
I find it on Solaris machines, but not FreeBSD ...
perhaps it is Solaris specific?