|
|
|
|
||||||
| comp.unix.shell Using and programming the Unix shell. |
![]() |
|
|
LinkBack | Outils de la discussion |
|
|
#1 |
|
Messages: n/a
Hébergeur: |
OK, let me rephrase that.
Why can't I feed the output of the date command to set the date ? For instance something like that: date $( ssh user@reference "date" ) Yes, I know I can use +"%m%d%H%M%Y.%s" to output the format expected as input, BUT that still leaves out the problem of the time zone. The command date doesn't seem to set the timezone so that pretty much renders this attempt plain wrong if both machines are not already configured with proper and identical timezone... The closest is: date -u $(ssh guinevere@distill "date -u +\"%m%d%H%M%Y.%s\"" ) (yes, I know about ntp, but that's not my question). -- Guillaume Dargaud http://www.gdargaud.net/ |
|
|
|
#2 |
|
Messages: n/a
Hébergeur: |
On 2008-05-05, Guillaume Dargaud <use_the_form_on_my_contact_page@www.gdargaud.ne t> wrote:
> > > OK, let me rephrase that. > Why can't I feed the output of the date command to set the date ? > > For instance something like that: > date $( ssh user@reference "date" ) > > Yes, I know I can use +"%m%d%H%M%Y.%s" to output the format expected as > input, BUT that still leaves out the problem of the time zone. The command > date doesn't seem to set the timezone so that pretty much renders this > attempt plain wrong if both machines are not already configured with proper > and identical timezone... > > The closest is: > date -u $(ssh guinevere@distill "date -u +\"%m%d%H%M%Y.%s\"" ) > (yes, I know about ntp, but that's not my question). Doesn't that work, other than a possible second or two of network lag? Or you could try date $(ssh guinivere@distill "TZ=yourtimezone date +%m%d%H%M%Y.%s") |
|
|
|
#3 |
|
Messages: n/a
Hébergeur: |
>> date -u $(ssh guinevere@distill "date -u +\"%m%d%H%M%Y.%s\"" )
> Doesn't that work, other than a possible second or two of network lag? Well, 'almost': # ssh guinevere@distill date; date -u $(ssh guinevere@distill "date -u +\"%m%d%H%M%Y.%s\"" ); date; cat /etc/TZ Mon May 5 17:18:05 CEST 2008 Mon May 5 15:18:12 UTC 2008 Mon May 5 15:18:12 UTC 2008 CEST So the time is correct, but the timezone information is ignored. It may be a bug in uClibc. Or maybe I need to tell it explicitely to read TZ... > Or you could try > date $(ssh guinivere@distill "TZ=yourtimezone date +%m%d%H%M%Y.%s") Same thing: # date $(ssh guinevere@distill "TZ=CEST date +%m%d%H%M%Y.%s") Mon May 5 15:38:12 UTC 2008 date can show the timezone, so why can't it set it ? -- Guillaume Dargaud http://www.gdargaud.net/ |
|
|
|
#4 |
|
Messages: n/a
Hébergeur: |
Guillaume Dargaud wrote:
>>> date -u $(ssh guinevere@distill "date -u +\"%m%d%H%M%Y.%s\"" ) > >> Doesn't that work, other than a possible second or two of network lag? > > Well, 'almost': > # ssh guinevere@distill date; date -u $(ssh guinevere@distill "date -u > +\"%m%d%H%M%Y.%s\"" ); date; cat /etc/TZ > Mon May 5 17:18:05 CEST 2008 > Mon May 5 15:18:12 UTC 2008 > Mon May 5 15:18:12 UTC 2008 > CEST > > So the time is correct, but the timezone information is ignored. It may be a > bug in uClibc. Or maybe I need to tell it explicitely to read TZ... > >> Or you could try >> date $(ssh guinivere@distill "TZ=yourtimezone date +%m%d%H%M%Y.%s") > > Same thing: > # date $(ssh guinevere@distill "TZ=CEST date +%m%d%H%M%Y.%s") > Mon May 5 15:38:12 UTC 2008 > > > date can show the timezone, so why can't it set it ? Typically date/time is stored in the system clock as if it were UTC. Each process then can have its own concept of in which TZ that process is running. The representation of the UTC date/time can then be presented in which ever format the user chooses. But all the processes are working on the same date/time basis, UTC. At login your processes pick up their concept of a timezone in some way, maybe from /etc/localtime, or /etc/TZ, or /etc/default/??, or ??? I don't know your OS, so I don't know how your system does it. Once set, the timezone information for a process is part of its environment, not part of the systems environment, just that process. And as for exported variables, a child process can not affect the environment of its parent. So running date can change the hardware clock or the kernels copy of its value because it is specifically written to do that. But it can not change your shells timezone environment setting. BTW I don't recognize CEST as a timezone and my zoneinfo files do not show such a file name. The tzset man page notes that if the environment setting for the timezone is not recognized it defaults to UTC. Might that be the reason you keep seeing UTC output from date? |
|
|
|
#5 |
|
Messages: n/a
Hébergeur: |
> At login your processes pick up their concept of a timezone in some way, > maybe from /etc/localtime, or /etc/TZ, or /etc/default/??, or ??? Thank you for the cear explaination. I'll ensure TZ is correct before boot or application launch then. -- Guillaume Dargaud http://www.gdargaud.net/ |
|
|
|
#6 |
|
Messages: n/a
Hébergeur: |
2008-05-6, 16:59(+02), Guillaume Dargaud:
> >> At login your processes pick up their concept of a timezone in some way, >> maybe from /etc/localtime, or /etc/TZ, or /etc/default/??, or ??? > > Thank you for the cear explaination. > I'll ensure TZ is correct before boot or application launch then. I'd advise against setting TZ globally. That means that if you want to change TZ globally, you need to restart every application so that there environment be updated. Or set it to something like Local/MyTime so that you can change the definition of that. If TZ is not set, the time displaying functions generally get the timezone information from /etc/localtime. That file can be a symlink to /usr/share/zoneinfo/Europe/Paris (to be adapted on your system). That is equivalent to setting TZ to Europe/Paris, with the benefit that you can change it to something else and the new default being taken into account without needing a reboot. For the initial question, I don't think anyone mentioned the obvious answer: use the -u option for both dates: date -u "$(ssh other-server date -u +...)" Anyone mentioned NTP and ntpdate already? -- Stéphane |
|
|
|
#7 |
|
Messages: n/a
Hébergeur: |
On May 5, 9:42am, "Guillaume Dargaud"
<use_the_form_on_my_contact_p...@www.gdargaud.ne t> wrote: > OK, let me rephrase that. > Why can't I feed the output of the date command to set the date ? > > For instance something like that: > date $( ssh user@reference "date" ) > > Yes, I know I can use +"%m%d%H%M%Y.%s" to output the format expected as > input, BUT that still leaves out the problem of the time zone. The command > date doesn't seem to set the timezone so that pretty much renders this > attempt plain wrong if both machines are not already configured with proper > and identical timezone... > > The closest is: > date -u $(ssh guinevere@distill "date -u +\"%m%d%H%M%Y.%s\"" ) > > (yes, I know about ntp, but that's not my question). > -- > Guillaume Dargaudhttp://www.gdargaud.net/ Have you considered "setclock"? Simply issue "setclock PrimaryServer" while logged on to any other server in your network and those servers will attempt to get the right time from the PrimaryServer system. This is useful when you want to keep many UNIX hosts synchronized with the same time on one network. Example: we have an Oracle primary and standby server, and we like to keep the time the same on both so that the archive logs and date/time stamps of everything are going to match within a few seconds of each other. So we run "setclock" in the root crontab every night at a designated time. |
|
![]() |
| Outils de la discussion | |
|
|