Operating System - HP-UX
1836401 Members
2452 Online
110100 Solutions
New Discussion

Date/Time Info. from several servers

 
SOLVED
Go to solution
Sanjay Verma
Super Advisor

Date/Time Info. from several servers

Friends,
Any idea on creating script (Unix or NT) so as to get the date & time information from several servers?
Co-operation - The biggest chain reaction
18 REPLIES 18
Sanjay Verma
Super Advisor

Re: Date/Time Info. from several servers

+ I don't want to specify the passwd manually.....
Co-operation - The biggest chain reaction
Bill Hassell
Honored Contributor

Re: Date/Time Info. from several servers

Not necessary. NTP is the best protocol ever designed for syncing time between computers and is accurate to 128ms or better. For HP-UX, start by determining if you can talk to NTP servers on the Internet. On HP-UX, use this command:

ntpq -p ntp-cup.external.hp.com

If you have DNS problems, use the IP address:

ntpq -p 192.6.38.127

It should list the time servers used by ntp-cup. If instead it returns "Request timed out:, then you need to speak to your network administrator about allowing port 123 for NTP to be opened for your computer. Your administrator may have already setup NTP on the company's firewall in which case, check it out with ntpq -p firewall_address.

Once you see an output like this (formatting will be compressed here in the forums):

remote refid st t when poll reach delay offset disp
==============================================================================
-thesimonet.org .TRUE. 1 u 14 64 377 102.28 6.415 1.66
*PALISADE(1) .GPS. 0 l 29 32 377 0.00 0.010 0.02
+bigben.cac.wash .USNO. 1 u 13 128 377 34.26 -1.709 0.15

you are ready to sync your computer. Start by editing /etc/ntp.conf. Since there are a lot of comments, you may wish to delete everything in ntp.conf (a backup copy is stored in /usr/newconfig/etc) and just put these lines:

server ntp-cup.external.hp.com
server 127.127.1.0
fudge 127.127.1.0 stratum 10
driftfile /etc/ntp.drift

Then edit the startup config file: /etc/rc.config.d/netdaemons and edit these lines:

export NTPDATE_SERVER=ntp-cup.external.hp.com
export XNTPD=1

Now make sure your system does not have any date-sensitive programs running (like databases). Then start NTP services with:

/sbin/init.d/xntpd start

This script is run automatically at bootup. It will step-change (jump) your current time to match the NTP server. From now on, time will be within 128ms accuracy.

As far as NT or Win2K, there is no support for the NTP protocol built-in. You'll have to find freeware or a priced product to support NTP. WinXP has NTP built-in.

If you have a large number of computers in your company, you may want to look at stratum levels for distributing NTP services. Your HP-UX system is already acting as an NTP server so you may want to point your other HP-UX system at that server. And in your current server, you should add additional NTP sources (5 to 7 is a good number). NTP is a very sophisticated protocol and knows how interpret time queries from various sources and survive loss of sync as well as large differences between servers.

To learn more about NTP, go to the source: http://ntp.org This is also the location to find other NTP servers on the net.


Bill Hassell, sysadmin
Sanjay Verma
Super Advisor

Re: Date/Time Info. from several servers

Bill, I really appreciate for you quick & comprehensive information and will look for implementing that in my own environment.

At this stage, I would like to check the dates (timestamp) on 3 servers where I've access as "root". Now the problem with using this command:

rexec SERVER-1 -l root -n date

is that it asks for the root password which I want to avoid. Is there any way to bypass asking the passwd?
Co-operation - The biggest chain reaction
Sanjay Verma
Super Advisor

Re: Date/Time Info. from several servers

I've been able to look for the command "remsh".

Friends - Is there any way I can look for the timestamp on the NT box from Unix machine?? Will appreciate very very much for the solution...
Co-operation - The biggest chain reaction
Steven E. Protter
Exalted Contributor

Re: Date/Time Info. from several servers

Just so that you understand, betting the date and time is not the real problem.

Three systems sitting in the same building should have the same system time under almost any circumstances. Bill's answer is the right answer.

It can cause significant problems when a file is transferred from server a to server b and was created in the future for example.

http://developer.novell.com/research/appnotes/1999/july/03/02.htm
http://www.eecis.udel.edu/~mills/

SEP
Steven E Protter
Owner of ISN Corporation
http://isnamerica.com
http://hpuxconsulting.com
Sponsor: http://hpux.ws
Twitter: http://twitter.com/hpuxlinux
Founder http://newdatacloud.com
Sanjay Verma
Super Advisor

Re: Date/Time Info. from several servers

Steven,
Pl. understand my requirement at this point in time. It's NOT necessary that all the 3 servers will have the same time stamp - the reason being - some of the servers are managed by the Telephone service provider for xyz purposes. At this stage, I want to check and make sure that the timestamp is all synchronized - and if not, will implement Bill's solution.

But the requirement is:
Can I create a script on NT box to check the time stamp on the Unix servers - OR vice-versa? I've used "remsh" but want to check the cross-platform systems i.e., NT to Unix or Unix to NT.
Co-operation - The biggest chain reaction
Donny Jekels
Respected Contributor

Re: Date/Time Info. from several servers

not sure if you use ssh for all your boxes.

anyway here is a quick way to check the time on all your boxes


for x in `cat myserverlist`
do
echo $x
ssh $x "ntpq -p; date"
done | tee ntp.stats

mailx myemail@mycomp.com < ntp.stats


peace
Donny
"Vision, is the art of seeing the invisible"
Bill Hassell
Honored Contributor
Solution

Re: Date/Time Info. from several servers

Sorry for the misunderstanding. rexec work fine as long aqs the remote machines allow rexec. What you must do is to create a file called .netrc in your $HOME directory. It must have an entry for each computer in the form: machine_name, user_name and password in this format:

machine snoopy login root password IamAdawg

After creating this file, IMMEDIATELY change the permissions to 600, owned by yourself. Then try the command with:

rexec some_machine date

and you will see the date. If the command asks for the password, the permissions for .netrc are probably wrong. If it says connection refused or closed, then rexec is not permitted.

rexec is the preferred 'r' command to use when maintaining multiple hosts as each host does not need a .rhosts file. The local machine should be secured of course. The best choice is always to use SSH but this requries SSH to be installed on all the machines.


Bill Hassell, sysadmin
Sanjay Verma
Super Advisor

Re: Date/Time Info. from several servers

Thanks Bill for the information. Again, is there any way to run the "date" command on the NT box from Unix??
Co-operation - The biggest chain reaction
Bill Hassell
Honored Contributor

Re: Date/Time Info. from several servers

NT isn't like Unix. It does not support Unix commands by default. You may be able to configure remote shell (remsh from the HP-UX side) and hopefully it will go to a DOS-like command line. Sorry, I don't know how it could be done. Windows isn't very command-line friendly.


Bill Hassell, sysadmin
Donny Jekels
Respected Contributor

Re: Date/Time Info. from several servers

cygwin is your answer.

install cygwin on your nt box, and work on it as if its a real OS(UX) :o(

install ssh, and all the goodies.
http://www.cygwin.com/

you'll be glad you did.

peace
Donny
"Vision, is the art of seeing the invisible"
Sanjay Verma
Super Advisor

Re: Date/Time Info. from several servers

Friends,
My requirement is not the emulation of Unix like env. in Windows. But the requirement is:
> From Unix server, can I get the information of my NT servers i.e, date/time, ip address etc. etc.?
Co-operation - The biggest chain reaction
Donny Jekels
Respected Contributor

Re: Date/Time Info. from several servers

then we teach windows to use ntp 4

same for loop, this time to your windows boxes.


for x in `cat mywin32boxes'
do
echo $x
ssh $x "ntpq -p; date"
done

peace
Donny
"Vision, is the art of seeing the invisible"
Donny Jekels
Respected Contributor

Re: Date/Time Info. from several servers

sanjay,

the only way i can think of right now is the use of ssh into your windows box and run the native windows date command.

however to ssh into the windows box you must install cygwin 1st, even though you probibly never will use unix emulation on the nt box.

unless you know of another way, let us know.

my 2 cents


"Vision, is the art of seeing the invisible"
Sanjay Verma
Super Advisor

Re: Date/Time Info. from several servers

Donny, Appreciate for your inputs. I agree with you.

I am still trying to achieve the results in one ago - that is, create a single script in Unix, which gets the date/time information from both Unix & NT boxes and give me the results. How that sounds?
Co-operation - The biggest chain reaction
Sridhar Bhaskarla
Honored Contributor

Re: Date/Time Info. from several servers

Hi,

If you didn't disable the 'daytime' service on the unix system, you can do a 'telnet server 13' to get the date displayed without having to compromise on the security. I would write a small script that does a telnet to the each server at this port and puts them in a file. Then you can read that file to consolidate the information.

This doesn't work for NT machines. On Windows you have to use specialized softwares that will run either daytime|time service or sshd to enable you to get the information.

-Sri

You may be disappointed if you fail, but you are doomed if you don't try
Reid Orsten
New Member

Re: Date/Time Info. from several servers

As for the .netrc file, I'd suggest touching it, chmodding it, and then editing it. Maybe paranoid, but yeah.
Sanjay Verma
Super Advisor

Re: Date/Time Info. from several servers

Sridhar, Thanks for the info. Will wait for your script.
Reid, Can you be more specific about your comments?
Co-operation - The biggest chain reaction