The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
Google UNIX.COM


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
US timezone changes Mar 2007 hcclnoodles SUN Solaris 5 03-09-2007 09:46 PM
Timezone oss UNIX for Advanced & Expert Users 7 10-19-2005 11:20 PM
timezone eddyvdv UNIX for Dummies Questions & Answers 1 04-08-2002 02:46 PM
Timezone Novisern UNIX for Dummies Questions & Answers 5 03-28-2002 05:13 PM
Timezone ortsvorsteher UNIX for Dummies Questions & Answers 6 03-07-2002 02:08 AM

Reply
 
Submit Tools LinkBack Thread Tools Display Modes
  #1  
Old 02-04-2008
justsam's Avatar
Registered User
 

Join Date: Oct 2006
Location: Bangalore,India
Posts: 37
Timezone in +/-HHMM format

Hey guys,

is thr any easy way of fetching Timezone of the Solaris server in (+/-)HHMM format using shell scripts.

Say, if the current time zone is GMT, the script should return +0000
If the current timezone is Asia/Calcutta in /etc/TIMEZONE, the scripts has to return +0530
Reply With Quote
Forum Sponsor
  #2  
Old 02-04-2008
Registered User
 

Join Date: Jan 2008
Posts: 54
Quote:
Originally Posted by justsam View Post
Hey guys,

is thr any easy way of fetching Timezone of the Solaris server in (+/-)HHMM format using shell scripts.

Say, if the current time zone is GMT, the script should return +0000
If the current timezone is Asia/Calcutta in /etc/TIMEZONE, the scripts has to return +0530
Hi
use this command " date +%z "
Reply With Quote
  #3  
Old 02-04-2008
justsam's Avatar
Registered User
 

Join Date: Oct 2006
Location: Bangalore,India
Posts: 37
Hi jagnikam,

Thanks for the reply.
I tried it.
But the output is GMT not +0000
Reply With Quote
  #4  
Old 02-04-2008
...@...
 

Join Date: Feb 2004
Location: NM
Posts: 4,262
Straight shell does not do what you need. try perl:
Code:
#!/bin/ksh

get_tz()
{
perl -e '
     use POSIX;
     ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday, $isdst)=localtime(43200);
     ($sec1, $min1, $hour1, $mday, $mon, $year, $wday, $yday, $isdst)=gmtime(43200);      
     $diffmin=$min - $min1;
     $diff=$hour - $hour1;
     printf "%s%02d%02d\n", ($hour1 <= $hour)?"+":"-", abs($diff), abs($diffmin);
     '
}


mytimezone=$( get_tz)
echo "my time zone is: $mytimezone"
Reply With Quote
  #5  
Old 02-08-2008
Registered User
 

Join Date: Sep 2007
Location: Poland
Posts: 63
$ /opt/exp/gnu/bin/date +%z
-0500
$ /opt/exp/gnu/bin/date +%Z
EST

Make sure you are using GNU date.
Reply With Quote
  #6  
Old 02-08-2008
...@...
 

Join Date: Feb 2004
Location: NM
Posts: 4,262
You can reasonably expect a system to support POSIX specifications for the date command. POSIX does not specify a %z. That is a GNU extension. GNU date is a good program, but if he is on a multiuser system, getting GNU date installed may be neither practical nor allowed.

GNU date is clearly not what the OP is now using.
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools
Display Modes




All times are GMT -7. The time now is 01:43 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008. All Rights Reserved.Ad Management by RedTyger Visit The Complex Event Processing Blog

Content Relevant URLs by vBSEO 3.2.0