WelcomeWelcome | FAQFAQ | DownloadsDownloads | WikiWiki

Author Topic: Updating TZ through script  (Read 290 times)

Offline Mypresus

  • Newbie
  • *
  • Posts: 24
Updating TZ through script
« on: June 02, 2022, 07:57:33 PM »
Does anybody know of a way to change the environment variable through scripting?  Tried the attached test code however no luck. Thinking it may not be possible as scripts work in their own environment and can not pass to parent, but never know. Thought doesn't hurt to ask. The object of this little project is to change TZ without rebooting.   
Any feedback welcome.

Offline Rich

  • Administrator
  • Hero Member
  • *****
  • Posts: 10252
Re: Updating TZ through script
« Reply #1 on: June 02, 2022, 08:37:54 PM »
Hi Mypresus
... The object of this little project is to change TZ without rebooting.
I don't know if that's possible. You might check if you can use  /etc/timezone  and/or  /etc/localtime  instead of  tz.

Offline Mypresus

  • Newbie
  • *
  • Posts: 24
Re: Updating TZ through script
« Reply #2 on: June 02, 2022, 09:15:07 PM »
Hi Rich,
Thank you for your quick reply and advise.  Changing TZ through command prompt works fine for example using "export TZ=UTC" however, using a the script does not change it.   Changing both  /etc/timezone  and/or  /etc/localtime files require a reboot to take effect I have played around a bit with using  extlinux.conf  tz=xxxx and this creates the TZ environment variable and the etc/timezone file.  I have also created the TZ through a script in the profile.d which creates the TZ environment variable with no problems (which shifts TZ from sys cmd to the user environment).Once TZ variable is created wanting to change it through a script is the sticking point, it works fine when changing through command prompt. If i can overcome this problem then changing timezone without rebooting becomes possible.   Would be nice to add to TC but unfortunately this my not be able to be achieved.

Offline Rich

  • Administrator
  • Hero Member
  • *****
  • Posts: 10252
Re: Updating TZ through script
« Reply #3 on: June 02, 2022, 09:29:42 PM »
Hi Mypresus
... Changing both  /etc/timezone  and/or  /etc/localtime files require a reboot to take effect ...
Are you sure? I read somewhere that you should not set  tz  if using  /etc/timezone  and/or  /etc/localtime.
Changing the link to  /etc/localtime  should change the time.

Offline Mypresus

  • Newbie
  • *
  • Posts: 24
Re: Updating TZ through script
« Reply #4 on: June 02, 2022, 10:33:15 PM »
Hi Rich, I will do some further testing to make sure and will let you know, thanks for the update. :D

Offline curaga

  • Administrator
  • Hero Member
  • *****
  • Posts: 10678
Re: Updating TZ through script
« Reply #5 on: June 02, 2022, 11:32:13 PM »
No, you cannot change vars in the parent. The usual solution for user-env vars is to set them in the login scripts, and if they need changing, log out and back in.
The only barriers that can stop you are the ones you create yourself.

Offline Mypresus

  • Newbie
  • *
  • Posts: 24
Re: Updating TZ through script
« Reply #6 on: June 03, 2022, 12:23:11 AM »
Thank you Curaga you have confirmed what i was thinking with parent child but was looking for a solution.  I think I may have found a work around chance/create the etc/timezone file as per Rich suggestion then activate the date command which uses etc/timezone and should then sets the TZ variable.  I will test and confirm the results.

Offline Mypresus

  • Newbie
  • *
  • Posts: 24
Re: Updating TZ through script
« Reply #7 on: June 03, 2022, 01:05:30 AM »
 :'( Didnt work logout login is required for using timezone and date. You where correct Curaga. Doesn't look like it is possible to update TZ in a script.