Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

shell

Posted on 1999-07-15
2
Medium Priority
?
685 Views
Last Modified: 2012-06-21
How can I substract time (now) from a later time (20 minutes from now) and get the answer to another variable in a shell script.
0
Comment
Question by:riname
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 2

Accepted Solution

by:
bedot earned 40 total points
ID: 2011501
here a rustic example to do what you want:

# difftime volontarily rustic
# save IFS
OLDIFS=$IFS
# add : to IFS for date
IFS=\:$IFS
# get reftime from file reftime previously created
set `cat /tmp/reftime`
REFHOURS=$4
REFMINUTES=$5
REFSECONDS=$6
# get actual time
set `date`
HOURS=$4
MINUTES=$5
SECONDS=$6
# recall old ifs
IFS=$OLDIFS
# compute
DIFFHOURS=`expr $REFHOURS - $HOURS`
DIFFMINUTES=`expr $REFMINUTES - $MINUTES`
DIFFSECONDS=`expr $REFSECONDS - $SECONDS`
TOTSECONDS=`expr 3600 \* $DIFFHOURS + 60 \* $DIFFMINUTES + $DIFFSECONDS`
# use result
echo "$DIFFHOURS hours $DIFFMINUTES minutes $DIFFSECONDS seconds"


create a file reftime with time > /tmp/reftime
edit reftime with the time you want
run this program

root@med1091[/tmp]cat reftime
Thu Jul 15 16:59:42 METDST 1999


root@med1091[/tmp]difftime
3 hours 40 minutes 11 seconds
at all 13211 seconds

0
 
LVL 1

Expert Comment

by:Moondancer
ID: 6821631
This question was awarded, but never cleared due to the JSP-500 errors of that time.  It was "stuck" against userID -1 versus the intended expert whom you awarded.  This corrects that and the expert will now receive these points, all verified.

Please click on your Member Profile, select "View Question History" to navigate through any open or locked questions you may have to update and finalize them.
 
Thanks,
Moondancer
Moderator @ Experts Exchange
0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Let's say you need to move the data of a file system from one partition to another. This generally involves dismounting the file system, backing it up to tapes, and restoring it to a new partition. You may also copy the file system from one place to…
I have been running these systems for a few years now and I am just very happy with them.   I just wanted to share the manual that I have created for upgrades and other things.  Oooh yes! FreeBSD makes me happy (as a server), no maintenance and I al…
Learn how to get help with Linux/Unix bash shell commands. Use help to read help documents for built in bash shell commands.: Use man to interface with the online reference manuals for shell commands.: Use man to search man pages for unknown command…
Learn how to navigate the file tree with the shell. Use pwd to print the current working directory: Use ls to list a directory's contents: Use cd to change to a new directory: Use wildcards instead of typing out long directory names: Use ../ to move…
Suggested Courses

705 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question