ksh to check second time difference between two servers


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers ksh to check second time difference between two servers
# 1  
Old 05-28-2013
ksh to check second time difference between two servers

I am currently setting up a public key authentication between servers. The goal is to get the date via `ssh hostname date` on all the 4 remote servers , put the value in a text file on the central server and compare the date (specifically seconds) for each server date output to check if time is actually sync. I know there will be a second interval while logging in to the system via ssh and retrieving the time. But I am thinking of a margin like 3 - 5 seconds.

Is there any specific script to compare the output of date command and get the difference of seconds. I am thinking of creating a script to get the seconds via 'cut' command but it easily breaks if it reaches ":00" and the result will be inaccurate.

Thanks.

Last edited by Scott; 06-01-2013 at 03:50 AM.. Reason: Moved thread - Not an AIX issue
# 2  
Old 05-28-2013
If your machines have time server enabled, you could contact the UDP time port of those machines and get the 32-bit time in seconds since 1900.
But then it's UDP...
# 3  
Old 05-28-2013
Time service as suggested, or if not available maybe running date +%s if your date command on each supports it. That will give seconds since the epoch and you can just do integer compares.

If you are looking to keep your machines in synch as far as clock is concerned, I'd suggest looking at ntpdate to keep your clocks from straying too far at which point you wouldn't need to check and compare.
# 4  
Old 05-28-2013
Although it is not specified by the POSIX standards and the Single UNIX Specifications, many implementations of the date utility provide a %s format conversion specification that will return Seconds since the Epoch. (i.e., the command:
Code:
date +%s

will return the number of seconds since midnight on the morning of January 1, 1970 GMT.) This is a nice value to use for something like this since it is immune to timezone differences and is not affected by shifts to and from daylight savings time.

Another thing not specified by those standards is the network time protocol daemon. Look for an ntpd man page on your servers. If the man page is present ask your sys admins to be sure it is running on those servers.
# 5  
Old 05-28-2013
Quote:
Originally Posted by depam
difference of seconds
If you have the timestamps locally and you wanted to get the seconds difference between two, then something like this should work:
Code:
$ ts1=$(date +%s -d '2013-05-28 20:37:34')
$ ts2=$(date +%s -d '2013-05-28 20:37:54')
$ secs=$(( ($ts2 - $ts1) ))
$ echo $secs
20


Last edited by Scott; 06-01-2013 at 03:49 AM.. Reason: Removed FONT tags
# 6  
Old 05-29-2013
Since you are setting up ssh for automatic command execution I would recommend using dsh (distributed shell) to execute the commands in parallel - whatever that command may be. Then the output will be in one file and it should be easy to compare output.

On AIX 6.1 the fileset name is csm.dsh
On AIX 7.1 the fileset name is dsm.dsh (because csm is discontinued)

Hope this helps!
# 7  
Old 06-01-2013
Thanks a lot for all your replies. Its an interesting note to take a look at dsh, that will help a lot on retrieval of system information which can be run on parallel. Apparently, our Security Group, wouldn't allow us to use it due to some "security" concerns but its is best to use this tool somewhere else or other environment.

What I did for now is to create a script and like what other folks suggested, use epoch time as the baseline and do public key authentication to remote servers one by one and compare the date and time. There will be a second delayed so I put in my script to check clock times which are more than 3 seconds or less than 0 second and assume that time is not sync.
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Check/Parse log file's lines using time difference/timestamp

I was looking at this script which outputs the two lines which differs less than one sec. #!/usr/bin/perl -w use strict; use warnings; use Time::Local; use constant SEC_MILIC => 1000; my $file='infile'; ## Open for reading argument file. open my $fh, "<", $file or die "Cannot... (1 Reply)
Discussion started by: cele_82
1 Replies

2. Shell Programming and Scripting

Time difference between two time stamps

Hi Friends, I have 2 varaibles which contain START=`date '+ %m/%d/%y %H:%M:%S'` END=`date '+ %m/%d/%y %H:%M:%S'` i want the time difference between the two variables in Seconds. Plz help. (2 Replies)
Discussion started by: i150371485
2 Replies

3. Shell Programming and Scripting

Same KSH behaving differently on diff servers

HI all I have written a ksh to execute PL/sql procedure and generate the log file. The script is working fine to the extent of calling the taking input, executing PL/SQL procedure. On one server the log file is getting generated properly. i,e it shows the DBMS output . The log file size was... (9 Replies)
Discussion started by: ramakrishnakini
9 Replies

4. UNIX for Dummies Questions & Answers

Difference Between executing llike ./myscript.ksh and . ./myscript.ksh

Hi , What is the diffence between executing the script like ./myscript.ksh . ./myscript.ksh I have found 2 difference but could not find the reason 1. If i export a variable in myscript.ksh and execute it like . ./myscript.ksh the i can access the other scripts that are present in... (5 Replies)
Discussion started by: max_hammer
5 Replies

5. Shell Programming and Scripting

ksh connection to other servers

Hello, I am looking for a way for a server to launch a connection command to one of the other servers where the connection command has already embedded in it a server name, user name and a password. (2 Replies)
Discussion started by: LiorAmitai
2 Replies

6. Shell Programming and Scripting

How to calculate time difference between start and end time of a process!

Hello All, I have a problem calculating the time difference between start and end timings...! the timings are given by 24hr format.. Start Date : 08/05/10 12:55 End Date : 08/09/10 06:50 above values are in mm/dd/yy hh:mm format. Now the thing is, 7th(08/07/10) and... (16 Replies)
Discussion started by: smarty86
16 Replies

7. Shell Programming and Scripting

Difference between development and Production unix servers for a application??

Hi all I am running a major script of my application in development for implementing code changes for process improvement in time. The script runs in production once in a month . It takes 8 hours 30 mins in Production server . what surprice me is , when I run the same script in development server... (9 Replies)
Discussion started by: sakthifire
9 Replies

8. UNIX for Dummies Questions & Answers

3 servers 1 .ksh script

system = AIX How can I explain this..... Keep in mind I do not want to login to the boxes, persay, and that I am fairly new to scripting and unix. I want to use SSH. I have a script on server1, this is where I want it to run from. I have server2 and server3, where I want the script to... (2 Replies)
Discussion started by: cml2008
2 Replies

9. Shell Programming and Scripting

ksh: difference between $* and $@

Please ignore. I found the answer at: https://www.unix.com/shell-programming-scripting/24557-difference-between.html (1 Reply)
Discussion started by: JamesByars
1 Replies

10. Shell Programming and Scripting

ksh to run servers

I want to write a Kshell program which will start the servers(Oracle,DataIntegrator). Can anybody help me with this? I would appreciate your help. Thanks in advance (0 Replies)
Discussion started by: pari111222
0 Replies
Login or Register to Ask a Question