Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

TimeSet.pl

by PearlJamned (Initiate)
on Jul 16, 2002 at 15:54 UTC ( [id://182121]=sourcecode: print w/replies, xml ) Need Help??
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
    Looks nice, but what is rdate?
    It is not on my Cygwin machine or my Mandrake Linux machine...
      $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?

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: sourcecode [id://182121]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others wandering the Monastery: (4)
As of 2024-04-19 05:48 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found