Results 1 to 7 of 7
Hello everyone,
I'm in need of a script/command that will get the current time from a time server , add 10 minutes , and then set the adjusted time as ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
- 07-30-2012 #1Just Joined!
- Join Date
- May 2011
- Posts
- 4
Automatic time setting in CentOS
Hello everyone,
I'm in need of a script/command that will get the current time from a time server , add 10 minutes , and then set the adjusted time as the system time.
( I need the system time to be +10 minutes from the correct time )
I thought about using the ntpdate, to set the correct time,
then use some command to advance the time by 10 minutes,
and put it in a shell script that will be called periodically by cron.
Any help will be greatly appreciated,
- 07-31-2012 #2Trusted Penguin
- Join Date
- May 2011
- Posts
- 3,673
- 07-31-2012 #3Just Joined!
- Join Date
- May 2011
- Posts
- 4
The time server is a NTP server.
I've successfully updated the time using ntpdate,
but I can't seem to find the correct command to advance the time.
I've looked into 'time' and 'date'... with no results.
Also it would be better to get the correct time as a variable of some sort,add the 10 minutes and only then set it.
But I didn't come up with a way to just query the time with ntpdate.
Thanks a lot for helping,
- 07-31-2012 #4Trusted Penguin
- Join Date
- May 2011
- Posts
- 3,673
I know the date command does it for you, if you want to add Years, Months, or Days - I didn't see an example for adding seconds though.
i do a similar thing myself (get date from an ntpdate server then do something w/that). what i had to do is grep the output of the command for the time. here's an example:Also it would be better to get the correct time as a variable of some sort,add the 10 minutes and only then set it.
But I didn't come up with a way to just query the time with ntpdate.
Here's a tip: using the date command, you can convert the date from the above command (you might need to format it a little first) to a number of seconds (seconds since the Linux epoch) using the %s format parameter. Than add 10 seconds(or whatever) to the number of seconds. Then you have to use funky syntax to convert back from epochal linux seconds to a standard date/time string. See the bottom of this wiki for an example:Code:ntpdate -d 0.pool.ntp.org|grep originate\ timestamp
http://en.wikipedia.org/wiki/Date_%28Unix%29
- 08-01-2012 #5Just Joined!
- Join Date
- May 2011
- Posts
- 4
Thanks atreyu,
I've decided to go with the simpler solution :
#!/bin/sh
ntpdate 0.pool.ntp.org
date -s "10 minutes"
Thanks for the tip about the 'date' command being able to add time, that's exactly what I've wanted !
- 08-01-2012 #6Trusted Penguin
- Join Date
- May 2011
- Posts
- 3,673
- 08-01-2012 #7
Tbh, I dont like the above solution.
- you cannot run ntpd, which is the standard way of synchronizing time.
- a cron is used instead. But what does it do? It sets the correct time, then +10min.
So the server is jumping in time regularly.
This can confuse daemons.
And I am not only talking about timestamps for logfiles, but also e.g. timer, benchmarks,..
My suggestion would be to sync the time with ntpd,
but define a custom timezone, which is 10min ahead.
So the procedure would be to copy your regular zoneinfo file, then dump it, modify it, create a new binary file with the zic compiler and lastly of course set this custom file as /etc/localtime
These links might be a start:
tz database - Wikipedia, the free encyclopedia
TimeZoneChanges - Debian Wiki
Be aware, that certain tools like java maintain their own zoneinfo files.You must always face the curtain with a bow.


Reply With Quote

