Unix Programming - capturing the time stamp

This is Interesting: Free IT Magazines  
Home > Archive > Unix Programming > July 2006 > capturing the time stamp





You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

Author capturing the time stamp
pawan_test

2006-07-18, 1:29 pm

Hi All,

I am working on a korn shell script.
i have a file such as:
DS.PETSCO.20060601203514.20060531.ctl_20060717124431

i have 2 problems here.

1) i have to capture the time stamp from
the above file i.e this number 20060717124431.
format of time stamp is YYYYMMDDHHMMSS.

can anyone plz let me know how do i capture the time stamp.

2) the second problem is, i have to calculate the next 27 hours
from the above time stamp.

SAY time in the above timestamp is 12:44:31 so i have to add
27 hours to this time stamp.

Note:when i add 27 hours please note that date also changes.
so i have to echo the new date and time when i add 27 hours
to the exisitng time stamp.

can anyone plx let me know how I do it.

thanks
pavi

Rainer Temme

2006-07-18, 1:29 pm

pawan_test wrote:

> DS.PETSCO.20060601203514.20060531.ctl_20060717124431


> 1) i have to capture the time stamp from
> the above file i.e this number 20060717124431.
> format of time stamp is YYYYMMDDHHMMSS.


echo DS.PETSCO.20060601203514.20060531.ctl_20060717124431 |
awk -F . '{printf("%s\n",$3);}'

> 2) the second problem is, i have to calculate the next 27 hours
> from the above time stamp.


TSTAMP=20060601203514

YEAR=`echo $TSTAMP | awk '{printf("%s\n",substr($0,1,4));}'`
MONTH=`echo $TSTAMP | awk '{printf("%s\n",substr($0,5,2));}'`
DAY=`echo $TSTAMP | awk '{printf("%s\n",substr($0,7,2));}'`
HOUR=`echo $TSTAMP | awk '{printf("%s\n",substr($0,9,2));}'`
MIN=`echo $TSTAMP | awk '{printf("%s\n",substr($0,11,2));}'`
SEC=`echo $TSTAMP | awk '{printf("%s\n",substr($0,13,2));}'`

echo "$YEAR $MONTH $DAY $HOUR $MIN $SEC" |
awk '{ printf("%s\n",strftime("%Y%m%d%H%M%S",mktime($0)+27*3600)); }'

good look ... Rainer
pawan_test

2006-07-18, 1:29 pm

Thanks a lot

pavi
Rainer Temme wrote:
> pawan_test wrote:
>
>
>
> echo DS.PETSCO.20060601203514.20060531.ctl_20060717124431 |
> awk -F . '{printf("%s\n",$3);}'
>
>
> TSTAMP=20060601203514
>
> YEAR=`echo $TSTAMP | awk '{printf("%s\n",substr($0,1,4));}'`
> MONTH=`echo $TSTAMP | awk '{printf("%s\n",substr($0,5,2));}'`
> DAY=`echo $TSTAMP | awk '{printf("%s\n",substr($0,7,2));}'`
> HOUR=`echo $TSTAMP | awk '{printf("%s\n",substr($0,9,2));}'`
> MIN=`echo $TSTAMP | awk '{printf("%s\n",substr($0,11,2));}'`
> SEC=`echo $TSTAMP | awk '{printf("%s\n",substr($0,13,2));}'`
>
> echo "$YEAR $MONTH $DAY $HOUR $MIN $SEC" |
> awk '{ printf("%s\n",strftime("%Y%m%d%H%M%S",mktime($0)+27*3600)); }'
>
> good look ... Rainer


Sponsored Links






Free braindumps | Software forum | Database administration forum

Copyright 2003 - 2008 webservertalk.com