PHWinfo banniere

Titres
PORTAIL ANNUAIRE ARTICLES COMPARATEUR HÉBERGEURS DEVIS FORUMS RÉDUCTEUR D'URL
Précédent   PHWinfo > Forums Hébergement > Forum Serveur - Sécurité et techniques > comp.unix.shell > Why can't I use `date` to set the date ?
S'inscrire FAQ Membres Recherche Messages du jour Marquer les forums comme lus
comp.unix.shell Using and programming the Unix shell.

Why can't I use `date` to set the date ?

Réponse
 
LinkBack Outils de la discussion
Vieux 05/05/2008, 14h42   #1
Guillaume Dargaud
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Why can't I use `date` to set the date ?

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/


  Réponse avec citation
Vieux 05/05/2008, 15h25   #2
Bill Marcum
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Why can't I use `date` to set the date ?

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")
  Réponse avec citation
Vieux 05/05/2008, 16h40   #3
Guillaume Dargaud
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Why can't I use `date` to set the date ?

>> 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/


  Réponse avec citation
Vieux 06/05/2008, 12h29   #4
Jon LaBadie
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Why can't I use `date` to set the date ?

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?
  Réponse avec citation
Vieux 06/05/2008, 15h59   #5
Guillaume Dargaud
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Why can't I use `date` to set the date ?


> 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/


  Réponse avec citation
Vieux 06/05/2008, 16h30   #6
Stephane CHAZELAS
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Why can't I use `date` to set the date ?

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
  Réponse avec citation
Vieux 06/05/2008, 22h00   #7
steven_nospam at Yahoo! Canada
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Why can't I use `date` to set the date ?

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.
  Réponse avec citation
Réponse


Outils de la discussion

Règles de messages
Vous ne pouvez pas créer de nouvelles discussions
Vous ne pouvez pas envoyer des réponses
Vous ne pouvez pas envoyer des pièces jointes
Vous ne pouvez pas modifier vos messages

Les balises BB sont activées : oui
Les smileys sont activés : oui
La balise [IMG] est activée : oui
Le code HTML peut être employé : non
Trackbacks are oui
Pingbacks are oui
Refbacks are oui


Fuseau horaire GMT +1. Il est actuellement 22h15.


Édité par : vBulletin® version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC5 Tous droits réservés.
Version française #16 par l'association vBulletin francophone
PHWinfo est un site Éducation Sans Frontières ©2000-2008
Ad Management by RedTyger
©Tous droits réservés par les parties respectives
Page generated in 0,15574 seconds with 15 queries