LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 10-08-2013, 07:53 AM   #1
Jakkie
LQ Newbie
 
Registered: Jan 2012
Posts: 26

Rep: Reputation: Disabled
Execute script between defined time frame.


Howzit guys,

Im struggling with time functions. What I want to achieve is to have a script that will be execute at random times by a user, but I need a check inside the code to make sure that it can only be invoked between a certain time of the day. Lets say someone runs it at 8am and the time span in the script is from 6am to 10am, then the script must run as normal. Any other time outside this window should exit the script with a message. I know I should put the current execution time in a variable and then compare bewteen the lower and upper time variables to determine whether the current time it between these times, but Im not sure how to do that. Im not worried about date, just time. Any halp will be appretiated.

Thanks,
J
 
Old 10-08-2013, 08:12 AM   #2
pan64
LQ Guru
 
Registered: Mar 2012
Location: Hungary
Distribution: debian i686 (solaris)
Posts: 8,491

Rep: Reputation: 2429Reputation: 2429Reputation: 2429Reputation: 2429Reputation: 2429Reputation: 2429Reputation: 2429Reputation: 2429Reputation: 2429Reputation: 2429Reputation: 2429
What have you made so far? You can check the man page of the date command (take care about the format, for example %s)
 
Old 10-08-2013, 08:23 AM   #3
Jakkie
LQ Newbie
 
Registered: Jan 2012
Posts: 26

Original Poster
Rep: Reputation: Disabled
Hi,

Thanks for the reply. I've done the execution part so far. In other words, when you execute it, it does what it's suppose to. Does not matter how many times you execute or when you execute, the code works nicely. I want to go one step further now by adding the "time check". On that, I have done nothing yet. Not really sure what to do. I guess I will use the result of the calculation between the current time and start/end time-span in an "if" statement to exit of execute the actual code.

Do you want to see the code thus far (without the time calculation)?

J
 
Old 10-08-2013, 08:27 AM   #4
pan64
LQ Guru
 
Registered: Mar 2012
Location: Hungary
Distribution: debian i686 (solaris)
Posts: 8,491

Rep: Reputation: 2429Reputation: 2429Reputation: 2429Reputation: 2429Reputation: 2429Reputation: 2429Reputation: 2429Reputation: 2429Reputation: 2429Reputation: 2429Reputation: 2429
You explained what to do in your first post.
use date +%s (or similar) to get time values and compare it to your given values. Have you tried to implement that?
 
Old 10-08-2013, 08:29 AM   #5
Jakkie
LQ Newbie
 
Registered: Jan 2012
Posts: 26

Original Poster
Rep: Reputation: Disabled
Hi,

Nope, not yet, but will try that now. Thanks for the advise.

Cheers,
J
 
Old 10-08-2013, 08:32 AM   #6
pan64
LQ Guru
 
Registered: Mar 2012
Location: Hungary
Distribution: debian i686 (solaris)
Posts: 8,491

Rep: Reputation: 2429Reputation: 2429Reputation: 2429Reputation: 2429Reputation: 2429Reputation: 2429Reputation: 2429Reputation: 2429Reputation: 2429Reputation: 2429Reputation: 2429
that's fine, ask if you are in doubt, or need help, but we will not implement it for you....
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
UDEV takes more time to execute at boot up time.Can anyboby help me to reduce dis tim pabansal Linux - General 3 09-30-2011 07:45 AM
script taking long time to execute smritisingh03 Linux - Newbie 6 01-25-2011 12:08 PM
script to execute a command based on the last modified time of a folder midadala Linux - Newbie 1 10-19-2010 08:28 AM
Run one script, but execute commands at the same time Micro420 Programming 8 07-18-2007 01:05 AM
execute php script by a time () afbase Linux - General 1 12-30-2006 04:30 PM


All times are GMT -5. The time now is 09:15 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration