Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I really need your help on a job of setting timezone and time on a router using Linux OS remotely from Web ( Linux OS based on Linux Kernel 2.6.30).
For fulfilling this job, I use CGI and Shellscript. Below are steps:

  1. Get Time, Timezone info from Browser
  2. Execute CGI to set time (using C)
  3. CGI executes Timezone_Setting shellscript

Here is what I'm doing for the script in step 3:

The parameter($1) is one of the following string (A):
"GMT-12", "GMT-11", "GMT-10",..."GMT", "GMT+1",.. "GMT+12".

It seems that I can use the following to set timezone:

ln -sf /usr/share/zoneinfo/Japan /etc/localtime

Questions:
1) Am I doing the right way?
2) How can I use the command above with my A strings correctly?

Note: In the above command, "Japan" is one of the files in my "/usr/share/zoneinfo" directory. And I can do a conversion before using the command like:

"GMT-9" <-> Japan

"GMT-5" <-> EST
( etc. )

but It seems not the good solution.

share|improve this question
add comment

1 Answer

up vote 1 down vote accepted

How to set the timezone depends on what C library your router uses. With Glibc, the C library used on non-embedded Linux systems, /etc/localtime is a symbolic link to a file under /usr/share/zoneinfo, or a copy of one. With uClibc (the one my home router uses), the time zone information is in /etc/TZ and is stored as a TZ environment variable specification (see below). Check which method your router uses. If your router uses Glibc, your approach looks correct.

GMT+9 and Japan are different time zones. GMT+9 means a time zone that is always 9 hours ahead of GMT. Japan means whatever time it is in Japan, taking DST and any past and future time zone change in Japan. Oh, and GMT-9 the wrong way round.

If you only need the timezone to be set in a particular program, run it with the TZ environment variable set to the timezone name or specification. For example, a timezone specification for the current DST rules of most Western Europe countries looks like this:

TZ=CET-1CEST,M3.5.0/2,M10.5.0/3

meaning the timezone is called CET, corresponds to UTC+1 (i.e. CET - 1 = UTC), and the timezone is CEST (with a default +1 hour offset) between the last Sunday of March at 2am and the last Sunday of October at 3am. For a simple year-round offset, you can use a setting like

TZ='<GMT+9>-9'
share|improve this answer
    
thanks for the answer. Is there any way to set TZ depending only on GMT+/-. I meant I don't care about the country but only "GMT-12"->"GMT+12". Something likes: if I set time to 10:00:00 and GTM+1=> I assume the current time: 9:00:00 in GTM+0 –  sees Sep 3 '11 at 8:56
    
@sees I've updated my answer to describe the TZ environment variable, it should do the trick. –  Gilles Sep 3 '11 at 10:17
    
thanks. Will try to use it –  sees Sep 3 '11 at 11:39
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.