Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Calculating time

Status
Not open for further replies.

jwant

Technical User
Jul 2, 2001
17
0
0
US
I need to be able to look at what time it currently is and determine if a specified amount of time has passed, say 15 minutes.
 
In ksh you can play with the
Code:
 SECONDS
buil-in variable.
Otherwise you can use the
Code:
 date
command.
man ksh
man date

Hope This Help
PH.
 
Let me clarify. I want a job to run every fifteen minutes. So, it will run on 0, 15, 30, and 45 of each hour. How do I do this? I know how to get seconds and minutes and hours and all that. But how do your calculated that fifteen minutes or say 5 minutes have passed?
 
man cron

vlad
+----------------------------+
| #include<disclaimer.h> |
+----------------------------+
 
Ok, this is what I did I used the function modulus.

if [ `expr $MIN % 15` = 0 ] # this determins if there is
# a remainder.
then
succcess
else
fail
fi

By determining the remainder I can tell whether the minutes are a multiple of 15 or not. So, 30 will return a 0 and so on. I hope this helps someone else.
 
Listen to the responses! This kind of thing is done with cron. You just need to create a script to do what you want one time with no time logic built into it. Then put an entry in your crintab like this...
Code:
   0,15,30,45 * * * * myscript.sh >> myscript.log 2>&1
This will run [tt]myscript.sh[/tt] every 15 minutes.

Otherwise you need to either keep submitting your script every minute and have it fail when it's not MOD 15 = 0, or have it in some busy loop.

Believe me, cron is cleaner and more reliable than trying to code this yourself.

Hope this helps.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top