cancel
Showing results for 
Search instead for 
Did you mean: 

easy unix time change

SOLVED
Go to solution
Olivier Drouin
Trusted Contributor

easy unix time change

Hi,
My memory is tricking me. I knew a way in solaris to change the date/time of a system in the shell of a user.

The machine time itself is still alright but it can be ahead a day or two for a sub-shell. ( I'm writing a script that delete log files after n-days, thats why I need this ).

It was only a matter of setting an environment variable ( TIMEZONE ? TZ ? ).

Somebody knows ?
12 REPLIES
Mark Grant
Honored Contributor

Re: easy unix time change

The TZ variable is only far adding and subtracting hours from the system clock. You shouldn't really use it for dealing with clock drift!

You shoudld set up "ntp" and synchronize your time with a public "ntp" server.

Oh and remember to synch your hardware clock.
Never preceed any demonstration with anything more predictive than "watch this"
Martin P.J. Zinser
Honored Contributor

Re: easy unix time change

The command to change the time on the commandline would be date -s . I do agree that setting up NTP is the much preferrable solution.

Greetings, Martin
Huc_1
Honored Contributor

Re: easy unix time change

Best is ntp but as a one of

Man rdate

ex: (just to see other node (time server) date/time

rdate -p 'remote_node'


J-P
Smile I will feel the difference
Olivier Drouin
Trusted Contributor

Re: easy unix time change

No guys you dont get my problem. My systems uses NTP and are all in sync.

I just want to "emulate" the time in a user subshell.

Huc_1
Honored Contributor

Re: easy unix time change

Sorry if I sound a bit dumm, I probably am !

What do mean by emulate in a sub-shell


J-P ( Is confused now !)
Smile I will feel the difference
Olivier Drouin
Trusted Contributor

Re: easy unix time change

Say the daemon on the machines are still on the correct time ( set be NTP ) so the logfiles are not f***** and creation/modification date of files is correct.

Now I login on the machine. ssh user@mybox. Everything that I start in this sessions is "subshell", ie: everyting I run or do is a child/fork of the "bash" instance I created when I log on.

Now I want everything in this session to use a time ( `date` output for example ) different than the real time of the machine that the other users/process/daemon.

I know it sounds silly but it can be done, I already did it but I just dont rememeber how.

BTW, for a dumb you have many karma points ! ;-)
Olivier Drouin
Trusted Contributor

Re: easy unix time change

I need this because I'm writing a script that deletes logifles after, say, 5 days.

Now I really dont want to 'touch' some files. Wait 5 days to test my system. And wait until next tomorrow if something doesnt work.

I want to:

1 go backward 5 days,
2 'touch' some files.
3 Reset the good time.
4 Test my script.
5 And repeat if I made a mistake.
Tony Contratto
Respected Contributor
Solution

Re: easy unix time change

Hi Olivier,

Why not just use touch to create the files with whatever date you want. Check the man page for touch for details, but something like the following should work for you.

touch -amt 200312011300 test.file

That should create a new file named test.file with an access and modified time of 1pm on Dec 1, 2003.

--
Tony
got root?
Olivier Drouin
Trusted Contributor

Re: easy unix time change

good! thanks!
Martin P.J. Zinser
Honored Contributor

Re: easy unix time change

How about touch -d to create the files with the correct time in the first place for the testing?
Olivier Drouin
Trusted Contributor

Re: easy unix time change

good idea for GNU tools. Unfortunately I'm working on a x86-solaris-8 box without gnu tools.
Martin P.J. Zinser
Honored Contributor

Re: easy unix time change

Hello,

well date is is part of the sh-utils
(see ftp://ftp.gnu.org/gnu)

You could try to build a date executable for x86 Solaris and use this for testing.

Greetings, Martin