1

Previous colleague set up cron job every 5 min for 24 hrs. Now I need to modify this only running between 7am to 7pm.

I had never learned cron job so I googled and tried but it didn't work.

Task Scheduler is set as below

  • Begin the task
    On a schedule
  • Settings
    One time
  • Advanced settings
    Repeat task every 5 minutes for a duration of Indefinitely
    Stop task if it runs longer than 30 minutes
    Enabled

And I modified the batch file from

C:\PHP\php.exe -f C:\path\cron.php five-mins

to

*/5 7-19 * * * C:\PHP\php.exe -f C:\path\cron.php five-mins

Even I added */5 7-19 * * * to batch file, it doesn't work.

It would be appreciative if someone can help me. Thanks in advance and thanks for taking your time.

  • Try: stackoverflow.com/questions/4390617/… – Kinnectus Jun 11 '15 at 9:42
  • > Big Chris, thanks for the suggestion I had a look and this could be one of the solution however this time I will use RedGrittyBrick's batch file coding. Anyway thank you very much! – hasmai Jun 11 '15 at 10:51
2

Windows native job scheduler is not configured the same way as Unix/Linux cron,

You cannot change the scheduling by editing the contents of a batch file.

You have limited options in the Task scheduler

enter image description here

You could alter that batch file to exit early if the time of day is outside a specific range.

An answer in stackoverflow suggests

set "currentTime=%Time: =0%"
set flag=false
if %currentTime% geq 07:00 if %currentTime% leq 19:00 set flag=true
if %flag%==true (
   # your existing commands
   # go here
)
  • > RedGrittyBrick, thank you very much for your explanation and details. Yes it works great! I never thought I could use coding for batch file as I hadn't self-learned it yet. Again, I appreciated it Thank you! – hasmai Jun 11 '15 at 10:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.