Skip to content
View in the app

A better way to browse. Learn more.

Unraid

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

cron script does not output local time in docker

Featured Replies

Hi,

 

I just created a docker for duckdns (dynamic dns) that runs a script that saves the curl output to a log file with a time stamp.

 

Link here: https://registry.hub.docker.com/u/aptalca/docker-duckdns/ and here https://github.com/aptalca/docker-duckdns and template repo here: https://github.com/aptalca/docker-templates

 

When the script is run from cron, the "date" command used outputs UTC time instead of local time. But when I exec into the docker via (docker exec -it Duckdns bash) and run the script manually, it outputs the correct EDT time.

 

Any ideas how I can fix it so it would work for anyone installing this (not hardcoding the US New York timezone)?

 

Thanks

  • Author

Finally figured this out.

 

Unraid automatically passes the host timezone as an environment argument in the docker run command:

docker run . . . -e TZ="mylocaltimezone" . . .

 

This sets the timezone for the user space, but not the system. Meaning, (at least in debian based systems) /etc/timezone and /etc/localtime are still set to UTC. For any script that is run in the user space, the environment setting, the correct timezone is used. However, any script launched by cron uses the system setting, UTC.

 

So for cron scripts to use the local timezone, one must first set the system timezone upon container start.

 

in my dockerfile, I called for a "firstrun.sh", which includes the following three lines that retrieves the local timezone from the environment set by unraid, and sets the system timezone:

 

  echo $TZ > /etc/timezone
  export DEBCONF_NONINTERACTIVE_SEEN=true DEBIAN_FRONTEND=noninteractive
  dpkg-reconfigure tzdata

 

I hope it helps others

Archived

This topic is now archived and is closed to further replies.

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.