The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers
.
google unix.com



UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Date Calculations mitschcg UNIX for Dummies Questions & Answers 8 03-06-2009 04:40 AM
Time Calculations & Conversions Nysif Steve UNIX for Advanced & Expert Users 1 09-14-2007 11:07 AM
problem doing the time calculations in shell. jonathan184 Shell Programming and Scripting 3 05-16-2007 01:30 PM
Time difference calculations satnamx Shell Programming and Scripting 1 07-26-2006 07:44 AM
Float calculations sharmavr UNIX for Dummies Questions & Answers 1 07-26-2006 02:18 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 09-13-2007
Nysif Steve Nysif Steve is offline
Registered User
  
 

Join Date: Aug 2007
Location: Albany, NY
Posts: 26
Time Calculations

I'm trying to have a loop print out statistics every X number of seconds. How can I add a specific number of seconds to a time variable and make a comparison? Thanks ahead of time.

For example:
Code:

startTime = `date +%H%M%S`
currentTime = $startTime
executeTime = startTime + X   # X is equal to the number of seconds
until(( $currentTime >= $endTime))
do
     if (($currentTime = $executeTime))
     then
          .
          .
          .
          ((executeTime = $currentTime + X ))  # X is equal to the number of 
     fi

     currentTime = `date +%H%M%S`
done
  #2 (permalink)  
Old 09-13-2007
jim mcnamara jim mcnamara is offline Forum Staff  
...@...
  
 

Join Date: Feb 2004
Location: NM
Posts: 5,717
In general, when working with time like this, you convert current time(s) to the epoch time in seconds - ie. number of seconds since Jan 1 1970.
On linux (or if you have gnu date)
Code:
epoch_seconds=$(date +%s)
otherwise try perl
Code:
epoch_seconds=$(perl -e 'print time;')
epoch_seconds is now a number like 1189706758 that you can add seconds to.
  #3 (permalink)  
Old 09-13-2007
Nysif Steve Nysif Steve is offline
Registered User
  
 

Join Date: Aug 2007
Location: Albany, NY
Posts: 26
date +%s prints %s to the screen
  #4 (permalink)  
Old 09-13-2007
Nysif Steve Nysif Steve is offline
Registered User
  
 

Join Date: Aug 2007
Location: Albany, NY
Posts: 26
I ran the man command on the date function. It doesn't seem to have an option for epoch time. What you suggested sounds like it'd fit what I am trying to do perfectly. How do I check the version on the date function currently in place? Could it possibly be a different flag besides %s?
  #5 (permalink)  
Old 09-13-2007
Perderabo's Avatar
Perderabo Perderabo is offline Forum Staff  
Unix Daemon
  
 

Join Date: Aug 2001
Location: Ashburn, Virginia
Posts: 9,111
As Jim mentioned, %s is an extention only available on gnu sed. He also mentioned perl which may be a better option. Please tell us what OS you have so we don't have to guess which tools you have.
  #6 (permalink)  
Old 09-14-2007
Nysif Steve Nysif Steve is offline
Registered User
  
 

Join Date: Aug 2007
Location: Albany, NY
Posts: 26
The perl -e command is working. Thank you for your help.
Closed Thread

Bookmarks

Tags
linux

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 05:36 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0