The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
Google UNIX.COM


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
How to make a script run for a maximum of "x" number of hours only ScriptDummy Shell Programming and Scripting 7 10-23-2007 06:51 AM
Subtract 2 months from the date mahekr2000 UNIX for Advanced & Expert Users 5 07-23-2006 09:01 AM
Subtract Time xadamz23 Shell Programming and Scripting 4 12-03-2005 11:18 PM
Subtract two date in unix vanand Shell Programming and Scripting 1 06-18-2005 04:19 AM
How to subtract 2 hours from 'date' in shell ( /bin/sh ) script ? yairon UNIX for Dummies Questions & Answers 1 06-07-2001 12:23 PM

Reply
 
Submit Tools LinkBack Thread Tools Search this Thread Display Modes
  #1  
Old 08-16-2006
Registered User
 

Join Date: Jul 2006
Posts: 36
script for add and subtract two hours

i find a script to calculate hours of job i(nclude extraordinary)

i make a script to calculate add and subtract two hours (format hh:mm:ss)
Reply With Quote
Forum Sponsor
  #2  
Old 08-16-2006
...@...
 

Join Date: Feb 2004
Location: NM
Posts: 4,297
Do you know about time?
try:
Code:
time myscript.sh
Reply With Quote
  #3  
Old 08-16-2006
...@...
 

Join Date: Feb 2004
Location: NM
Posts: 4,297
Or try:
Code:
    start_time=`perl -e 'print time;'`
    myscript.sh
    elapsed_time=$(echo "`perl -e 'print time;'` - $start_time    | bc)
    echo "Total time in seconds: $elapsed_time"

Last edited by jim mcnamara; 08-16-2006 at 12:48 PM. Reason: inverted subtraction...
Reply With Quote
  #4  
Old 08-16-2006
vgersh99's Avatar
Moderator
 

Join Date: Feb 2005
Location: Boston, MA
Posts: 3,016
doesn't 'elapsed = finish_time - start_time' and not vice versa?
not sure if you need 'bc' - your math is integer math anyway.
Reply With Quote
  #5  
Old 08-16-2006
...@...
 

Join Date: Feb 2004
Location: NM
Posts: 4,297
Yup -vgersh - you're right.

Some shells do not do integer math beyond 255. I can't tell what shell.
Reply With Quote
  #6  
Old 08-16-2006
Registered User
 

Join Date: Jul 2006
Posts: 36
where is the code ???

time myscript.sh ????

where is the code ???

i search a ssh or ksh script Timesub(time1 time2 ) which return time1-time2

(two string :"hh.mm.ss")

can you help me ??
Reply With Quote
  #7  
Old 08-17-2006
Registered User
 

Join Date: May 2006
Posts: 101
the propper do to is using epoch. (seconds since 1.1.1970) because if you have DST is can
srew your script very badly. also the math is integer math and therefore very easy.

you can use date to convert from and into epoch.
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes




All times are GMT -7. The time now is 12:28 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008. All Rights Reserved.Ad Management by RedTyger Visit The Complex Event Processing Blog

Content Relevant URLs by vBSEO 3.2.0