Operating System - HP-UX
1833476 Members
3123 Online
110052 Solutions
New Discussion

change system time via crontab?

 
SOLVED
Go to solution
Mike_Ca Li
Regular Advisor

change system time via crontab?

change date of a HPUX 11i server via crontab:

I have a shell script which I want to run by crontab :
like
start:
#!/usr/bin/sh
date 07311600
end
to change date of server to July 31 2004 and I set job to run at
00 16 * * 2 /usr/local/bin/timescript
However the system time does not change.
Why would that be?
5 REPLIES 5
Steven E. Protter
Exalted Contributor

Re: change system time via crontab?

You can do anything witha s script. I don't think its a good practice to change system time with a cron script triggered by system time.

You can inadvertantly cause a loop.

Best that be done manually or via ntp(network time protocol).

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
Mike_Ca Li
Regular Advisor

Re: change system time via crontab?

I need to change the date and not the time.
wouldn't running

00 17 * * 2 /usr/local/bin/changetimescript

changetimescript:
date 07311700

provide a more accurate time change than doing typing command
date 07311700 at 16:59:50 from keyboard?
Michael Tully
Honored Contributor

Re: change system time via crontab?

Why not set up NTP to bounce of your router. It will take less than 5 minutes to set up.

If you have databases on your system, they don't take too kindly to have the time changed, forwards or backwards.
Anyone for a Mutiny ?
Muthukumar_5
Honored Contributor
Solution

Re: change system time via crontab?

hai,

cron will be working based on time and date informations. If we change the time and date with a script, in a cronjob, it will make effects on other jobs and crontab too.

I have checked the accuracy of date change on command line as,

# time date 073117342004
unable to write utmps record to wtmps database
unable to write utmps record to wtmps database
Sat Jul 31 17:34:00 PDT 2004

real 0.0
user 0.0
sys 0.0

It cannot write time into logs. But the amount of time needed to change the date and time is in 1 second (average) period only. So you can very well proceed on shell with super privillaged user.
Easy to suggest when don't know about the problem!
Thomas Bianco
Honored Contributor

Re: change system time via crontab?

seriously consider NTP. it's automatic, simple to configure and avoids that nasty tendancy of database to melt down when somewhat changes the system time.

http://www.ntp.org

all you should have to do is create a /etc/ntp.conf with a single line similar to the following

Server SourceNTP.Server.net

where sourcentp.server.net is the ip or DNS name of a NTP provider, probably within your company.

then start the deamon (/usr/local/bin/ntpd if i am not mistaken) and let it adjust the time.

as for accuracy, i have close to 400 NTP clients in this building, and none of them are more then 10 ms off from the atomic time.
There have been Innumerable people who have helped me. Of course, I've managed to piss most of them off.