niXforums Forum Index
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   PreferencesPreferences   Log in to check your private messagesLog in to check your private messages   Log inLog in 
·  nixdoc.net ·  man pages ·  Linux HOWTOs ·  FreeBSD Tips ·  Forums
navigation Forum index » Programming » shell
capturing the time stamp
Post new topic   Reply to topic Page 1 of 1 [3 Posts] View previous topic :: View next topic
Author Message
Glenn Jackman
*nix forums addict


Joined: 19 Apr 2005
Posts: 97

PostPosted: Tue Jul 18, 2006 6:27 pm    Post subject: Re: capturing the time stamp Reply with quote

At 2006-07-18 10:54AM, pawan_test <sridhara007@gmail.com> wrote:
Quote:
i have a file such as:
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.

As mentioned,
f=DS.PETSCO.20060601203514.20060531.ctl_20060717124431
timestamp="${f##*_}"

Quote:
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.

Tcl is good for datetime manipulation.

tclscript='
scan '"$timestamp"' {%4d%2d%2d%2d%2d%2d} Y m d H M S
set time [clock scan "$H:$M:$S $m/$d/$Y"]
set time_27 [clock scan "27 hours" -base $time]
puts [clock format $time_27 -format "%Y%m%d%H%M%S"]
'
new_timestamp=`echo "$tclscript" | tclsh`


--
Glenn Jackman
Ulterior Designer
Back to top
Chris F.A. Johnson
*nix forums Guru


Joined: 20 Feb 2005
Posts: 2268

PostPosted: Tue Jul 18, 2006 3:45 pm    Post subject: Re: capturing the time stamp Reply with quote

On 2006-07-18, pawan_test wrote:
Quote:
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.

file=DS.PETSCO.20060601203514.20060531.ctl_20060717124431
timestamp=${file##*_}

Quote:
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.

newhour=$(( $hour + 27 ))
day_increment=$(( $day + $newhour / 24 ))

For date arithmetic, use GNU date, or see the c.u.s FAQ,
<http://home.comcast.net/~j.p.h/cus-faq.html#6>, or chapter 8 of
my book (that chapter is on line).

--
Chris F.A. Johnson, author <http://cfaj.freeshell.org>
Shell Scripting Recipes: A Problem-Solution Approach (2005, Apress)
===== My code in this post, if any, assumes the POSIX locale
===== and is released under the GNU General Public Licence
Back to top
pawan_test
*nix forums beginner


Joined: 04 Oct 2005
Posts: 38

PostPosted: Tue Jul 18, 2006 2:54 pm    Post subject: capturing the time stamp Reply with quote

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
Back to top
Google

Back to top
Display posts from previous:   
Post new topic   Reply to topic Page 1 of 1 [3 Posts] View previous topic :: View next topic
The time now is Fri Nov 21, 2008 9:22 pm | All times are GMT
navigation Forum index » Programming » shell
Jump to:  

Similar Topics
Topic Author Forum Replies Last Post
No new posts Running php file everyday on scheduled time sachin PHP 1 Fri Jul 21, 2006 12:49 pm
No new posts Capturing user login Information of windows sachin PHP 3 Fri Jul 21, 2006 5:44 am
No new posts How to show the last time Solaris 8 machine was patched Arizona Solaris 2 Thu Jul 20, 2006 1:42 pm
No new posts anvil status reports not on time? Carlos Carvalho Postfix 5 Thu Jul 20, 2006 12:04 am
No new posts Warning when new attributes are added to classes at run time Matthew Wilson python 7 Wed Jul 19, 2006 8:42 pm

Unsecured Loans | Bad Credit Mortgages | Mortgages | Loans | Remortgages
Copyright © 2004-2005 DeniX Solutions SRL
 
Other DeniX Solutions sites: Unix/Linux blog |  electronics forum |  medicine forum |  science forum | 
Privacy Policy


Powered by phpBB © 2001, 2005 phpBB Group
[ Time: 0.1506s ][ Queries: 20 (0.0750s) ][ GZIP on - Debug on ]