![]() |
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| 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 |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
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
|
|
||||
|
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) Code:
epoch_seconds=$(perl -e 'print time;') |
|
||||
|
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?
|
![]() |
| Bookmarks |
| Tags |
| linux |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|