candreshidalgo
Posts: 16
Joined: Mon Mar 27, 2017 5:05 pm

run code in crontab between hours does not work

Mon Nov 27, 2017 1:29 pm

hello.

I want to run code in crontab between hours every 1 minute but it doesn't work. in reality the code
starts the job at the indicated time (10:00) but it doesn't finish its execution at the indicated time (19:00).

the last line in the crontab is :

* 10-19 * * * /usr/bin/python /home/pi/Desktop/detector.py

if anyone has any idea or solution, please reply

thanks

scotty101
Posts: 3649
Joined: Fri Jun 08, 2012 6:03 pm

Re: run code in crontab between hours does not work

Mon Nov 27, 2017 2:06 pm

Are you sure that your crontab expressions will do what you want it to?

* 10-19 * * * means “At every minute past every hour from 10 through 19.”

So the task will be run for the first time each day at 10:00 and run until the program stops, it will then try to run again at 10:01, 10:02, 10:03 etc until 18:59.

If your python script never ends (i.e. infinite loop), it won't be stopped by cron. Cron only starts tasks running.
Electronic and Computer Engineer
Pi Interests: Home Automation, IOT, Python and Tkinter

knute
Posts: 445
Joined: Thu Oct 23, 2014 12:14 am
Location: Texas
Contact: Website

Re: run code in crontab between hours does not work

Mon Nov 27, 2017 9:40 pm

candreshidalgo wrote:
Mon Nov 27, 2017 1:29 pm
hello.

I want to run code in crontab between hours every 1 minute but it doesn't work. in reality the code
starts the job at the indicated time (10:00) but it doesn't finish its execution at the indicated time (19:00).

the last line in the crontab is :

* 10-19 * * * /usr/bin/python /home/pi/Desktop/detector.py

if anyone has any idea or solution, please reply

thanks
I'm not a cron expert but I think 10-19 is 10 through 19 inclusive. Meaning 10:00 through 19:59.

candreshidalgo
Posts: 16
Joined: Mon Mar 27, 2017 5:05 pm

Re: run code in crontab between hours does not work

Sat Dec 02, 2017 12:23 am

yes my python script never ends (i.e. infinite loop),.
Is there a solution to this case?. Does anyone have a suggestion?.
thanks

RonR
Posts: 431
Joined: Tue Apr 12, 2016 10:29 pm
Location: US

Re: run code in crontab between hours does not work

Sat Dec 02, 2017 3:11 am

candreshidalgo wrote:
Sat Dec 02, 2017 12:23 am
yes my python script never ends (i.e. infinite loop),.
Is there a solution to this case?. Does anyone have a suggestion?.
Do your own time checks/timing in your python script, sleeping during inactive periods to give up the cpu. Launch your script from /etc/rc.local with a trailing '&' to have it detach and run separately.

scotty101
Posts: 3649
Joined: Fri Jun 08, 2012 6:03 pm

Re: run code in crontab between hours does not work

Mon Dec 04, 2017 11:10 am

candreshidalgo wrote:
Sat Dec 02, 2017 12:23 am
yes my python script never ends (i.e. infinite loop),.
Is there a solution to this case?. Does anyone have a suggestion?.
thanks
Schedule a second crontab task to occur at the end of the scheduled time.
This task should run a command to kill the existing application.
Have a read online for ways to kill running applications.
Here is one example https://stackoverflow.com/questions/406 ... ash-script
Electronic and Computer Engineer
Pi Interests: Home Automation, IOT, Python and Tkinter

Return to “Raspbian”