Linux – How to get the timezone of a system image

linuxscriptingtimezoneunix

I'd like to get the timezone of a system. Now some caveats…

  • Im using Linux, and the target systems will be UNIX.
  • I'll be using only system images, ie. not the live system, but the partitions will be mounted.
  • I'll eventually be scripting it.

I was thinking about using /etc/localtime, but sometimes this is a real file, and sometimes a symlink. In either case, I can't seem to get a description of the file format from which to parse.

Anyone have any ideas?

Thanks

Best Answer

That file is going to be in the tz file format which is a binary format. You can use DateTime::TimeZone::Tzfile to parse it if you know Perl. If it is a symlink it should not mater because if it is mounted you can just follow it.

Lastly, if you can control the image creation I highly recommend you just set the system time to UTC.