Hi mrn6430,
There are so many things wrong here that I don't know where to start...
In post #3 you said:
Quote:
Originally Posted by mrn6430
It is stored in a file originally in this format:
mmddccyyHHMMSS in a GMT format.
I storing the value from the file into a field:
At this point the output value is still in GMT. I tried your code as follows:
I get a value stored in NLOG_TM2 = (%m-0 %M:%Z)T
Thanks
Note that your code sets a variable named LOG_TIME to a value containing four strings with each string separated by a <space> character which you then describe (in the following comment) as a single string containing no <space>s???
Then you use cut to extract six fields from a variable named NLOG_TIME (which has not yet been set) and use the values you extracted from that unset variable to assign a value to NLOG_TIME which the following comment says is now in the form ccyy-mm-dd hh:mm:ss, but in all likelihood is instead the fixed string -- ::.
Note also that at this point, you still hadn't answered any of my questions in post #2 in this thread:
Quote:
What operating system are you using?
What output do you get from the command: date -"?"?
What shell are you using?
If you are not using a 1993 or later version of the Korn shell, does your system have one that you can use? (What output do you get from the command: ksh93 --version || ksh --version?)
Since you chose not to answer those questions, kshji tried twice to help you with suggestions that would work just fine with a 1993 or later version of the Korn shell, but will not work at all on the 1988 version of the Korn shell you're using.
Quote:
Originally Posted by kshji
Ksh, bash, all posix-sh you can use builtin substr:
Hi kshji,
The substring variable substitutions are present in many shells that meet POSIX shell requirements, but they are not required by the POSIX standards. (And, they are not present in ksh versions before 1993.)
Quote:
Originally Posted by mrn6430
It does not work:
I get this error "testzone.ksh[4]: NLOG_TME="${LOG_TME:4:4}-${LOG_TME:0:2}-${LOG_TME:2:2} ${LOG_TME:8:2}:${LOG_TME:10:2}:${LOG_TME:12:2}": bad substitution"
Note: When I do ksh --version nothing is returned. So ran this command to find out the ksh version
on my solris 10 unix server and the version is : @(#)Version M-11/16/88i
To bypass this issue I did this:
However, when I run it it does not work with the printf provided:
Here is the output:
2016-12-30 16:20:11
(%m-0 %M:%Z)T
Hi again mrn6430,
Of course it fails. As I said in post #2, the printf statement I suggested only works with a 1993 or later version of ksh. The @(#)Version M-11/16/88i version string from your Korn shell, shows that you are using a November 1988 version of ksh which does not know how to process printf '%(format)T' format conversions. (In fact, just knowing that ksh --version gives you no output tells us that your version of ksh is a 1988 or earlier version.)
You can try running your script with /usr/dt/bin/dtksh instead of ksh and see if that works. (Note that /usr/dt/bin/dtksh probably won't be present unless your sysadmin loaded the CDE option when they installed the Solaris System on your server.) Or, you can look for gdate. /usr/gnubin/date, or /usr/gnu/bin/date and use the suggestions provided by drl and jim mcnamara. But, none of these will work until you correctly set NLOG_TIME. (All three of the names listed above were used in various Solaris 10 installation options and your sysadmin might not have loaded any of them.) If you don't have a GNU date and don't have dtksh, you can write an easy C program to do the conversion for you that will work on any Solaris 10 system.
I've already explained why NLOG_TIME is not being set correctly, but there are probably ways to much more simply set NLOG_TIME than the code you have shown us so far. If you show us the contents of the file named by pathname named by the expansion of $DATA/filein.xml, we can probably give you a way to set NLOG_TIME much simpler and more efficient than what your script is currently doing.
Last edited by Don Cragun; 01-01-2017 at 01:39 AM..
Reason: Fix typo s/install/installed/
This User Gave Thanks to Don Cragun For This Post:
In fact, just knowing that ksh --version gives you no output tells us that your version of ksh is a 1988 or earlier version.
Actually not, the original ksh93 (thus dtksh) didn't implement --version yet.
Quote:
You can try running your script with /usr/dt/bin/dtksh instead of ksh and see if that works.
The original ksh93 wasn't supporting either printf as a builtin. It was introduced, including the %T format specification, in ksh93h released in 1999.
Quote:
Note that /usr/dt/bin/dtksh probably won't be present unless your sysadmin loaded the CDE option when they installed the Solaris System on your server.
CDE is likely there, as it is installed by default under most Solaris 10 instances. Only minimized, core system/reduced network rare installation are missing it.
Quote:
Or, you can look for gdate. /usr/gnubin/date, or /usr/gnu/bin/date
/usr/gnu is a Solaris 11 directory. On Solaris 10, gnu utilities are under /usr/sfw/bin but unfortunately, GNU date is not part of them. It might have been installed by the administrator from a freeware repository and in such case, might be under /usr/local/bin or /usr/csw/bin.
Quote:
Originally Posted by mrn6430
How can I convert the following date format:
New Log Date = 2016-12-30 23:50:33 GMT
from GMT time to local time?
Here is one way to do it using Solaris 10 standard tools:
I need away to convert the following GMT date and time value RAW_TME= 042720171530 "mmddccyyhhmm" to Localhost time. In this case it is in central time.
Here is what I came up with but it does not look efficient:
RAW_TME=042720171530
logmm=`echo $RAW_TME | cut -c1-2`
logdd=`echo $RAW_TME |... (4 Replies)
Gents,
Please can help with this.
the column in red is the local time
the column in blue is the GPStime
4153152529951 2/12/17 12:00:04.980 951 2960 41531.0 52529.0 1170882022980002
4108153261942 2/12/17 12:00:07.944 942 2959 41081.0 53261.0 1170882025944002
41511523611660... (7 Replies)
Hi Team,
We have written a perl script to perform the GMT to MST timestamp conversion.
Input: 2013-12-01T05:23:19.374
Output: need the given timestamp in MT (MST/MDT)
#!/usr/bin/perl
use strict;
use warnings;
use Time::Local;
#always gmt
#my $tval = '2013-12-01T05:23:19.374';
... (4 Replies)
Discussion started by: kmanivan82
4 Replies
4. Post Here to Contact Site Administrators and Moderators
Dear All,
Today, somewhere around 7:30 GMT (2:30 PM Eastern Time) www.unix.com will go down for what we hope is around 15 - 20 minutes as we change out some hardware on the server.
Thank you for your patience and support.
Neo (0 Replies)
Hi,
A few days ago I changed my CentOS box's timezone to -07:00.
Now the date commands output look like this (run almost simultaneously, less than 1 second delay)..
# date
Mon Sep 5 20:23:40 PDT 2011
# date -u
Tue Sep 6 03:24:05 UTC 2011
The hours difference seems correct, but why is... (2 Replies)
Hello,
Using AIX6.1 box.
I have UTC time value and need to convert it to local time value - I mean time zone and DST should be taken into consideration.
I hope it could be done using shell environment - I don't want to write a program.
thanks
Vilius
---------- Post updated at 02:30 PM... (2 Replies)
hi friends,
this is my first time with this type of script so please pardon my ignorance. i have this script in which a piece of code needs to be added which can have the Asia/Hong kong time as well. system date and format is GMT so no problem with GMT and even EST is covered..i have ato add new... (5 Replies)
hello gurus,
i want a perl/shell script which once invoked should convert a set of EPOCH timestamps to local time ( IST..i want) .
how does it work ,i have an idea on that..but writing a perl/shell script for it is not possible for me...so i need help for the same.
my exact requirement is... (2 Replies)