- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - Linux
- >
- Re: Get Time
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Discussions
Discussions
Forums
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО05-02-2007 07:39 PM
тАО05-02-2007 07:39 PM
Here's the script - feel free to give your feedback on this. Tested only on linux as of now.
>>
[ramd@nt14115 ramd]$ cat time.sh
#!/bin/bash
ZDUMP=/usr/sbin/zdump
if [[ $# = 0 ]]; then
echo "Error: $0
exit 1
fi
city=$1
if [[ -n $city ]]; then
tzfiles=$(find /usr/share/zoneinfo | grep -i $city)
if [[ -n ${tzfiles} ]]; then
for tzfile in ${tzfiles}
do
${ZDUMP} ${tzfile}
done
fi
fi
exit 0
[ramd@nt14115 ramd]$
<<
Run as follows -
>>
[ramd@nt14115 ramd]$ ./time.sh
Error: ./time.sh
[ramd@nt14115 ramd]$ ./time.sh Sara
/usr/share/zoneinfo/Europe/Sarajevo Thu May 3 09:25:26 2007 CEST
/usr/share/zoneinfo/posix/Europe/Sarajevo Thu May 3 09:25:26 2007 CEST
/usr/share/zoneinfo/right/Europe/Sarajevo Thu May 3 09:25:04 2007 CEST
[ramd@nt14115 ramd]$
<<
Hope this helps.
- ramd.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО05-02-2007 08:31 PM
тАО05-02-2007 08:31 PM
Re: Get Time
regards,
ivan
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО05-02-2007 08:52 PM
тАО05-02-2007 08:52 PM
Solution$ zdump Europe/Stockholm
Europe/Stockholm Thu May 3 10:22:35 2007 CEST
$ TZ=Europe/Stockholm date
Thu May 3 10:22:47 CEST 2007
So, you don't need to use zdump. With "date", you can use format strings to get the date in exactly the way you like, so it's more flexible to use "date".
If I needed a script like this, the essential functionality would be something like:
timezone="$1"
shift
echo -n "${timezone} "
TZ=${timezone} date "$@"
If a check for timezone's existence is required, that could be done by digging around /usr/share/zoneinfo as in your script.
The TZ environment variable is not "special" or "holy" in any way. If you're in a different timezone from the server you're using or you need to use a different timezone for some other reason, you can override the default with the TZ variable. Just remember that things like crontab always use the system-wide default timezone.
In Linux (and some other unixes), there is a way for the sysadmin to choose a default timezone which is automatically used if TZ is unset; in other unixes, the TZ variable is the primary way of setting the timezone.
If the unix variant you're using has time zones specified as "continent/capital", it usually understands that format in the TZ variable too. Other unixes will understand only "CET-1CEST" style TZ values.
In your link, the writer of the webpage was not interested in the current time, but the past and future times of standard <-> DST time transitions. This requires the use of zdump.
MK
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО05-04-2007 06:28 PM
тАО05-04-2007 06:28 PM
Re: Get Time
I didn't really mean to re-invent the wheel, and in the script all I do is to reduce the effort for the user to search for a city name within /usr/share/zoneinfo/... and print current time of that city/tz.
MK, really value your inputs. Thanks.
Ivan, i would not venture to post this yet in the other thread - maybe after i make the changes that MK suggests. But thanks for the idea.
- ramd.
'Learning more everyday.'
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-09-2009 02:44 PM
тАО04-09-2009 02:44 PM