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
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.
Do you know what flavor of UNIX these are?
In addition to /etc/localtime,
/etc/sysconfig/clock
/etc/timezone
The cruel way .... :p If mount is readonly, touch a file and afterwards ... ls -lah ....
then you 'll have the time that the file was created. Meaning ... system's time +/- some seconds.
Or somehow, try to modify something explicitly, or implicitly and see the time :>
A simple way to handle this on Linux systems is to use the file command;
or
However as you may be using images of UNIX systems (I am hoping its Solaris as thats as much as I am familiar with) it may be slightly different.
Without actually writing the script for you, here is my take on it in pseudo code
Yes its less than elegant but you shoudl get my drift. So you can make some assumputions on the os based upon the mount.
The process would be same for say a Solaris mount, you could work out where the file is, use the file command to determine the filetype and from there either just get its contents with cat or grep ^TZ
Hope that helps.
From the command line you can get it in a safer way than reading /etc/localtime by running: