I want crontab to execute daily three separate jobs, each corresponding to a python script. The first requires a few minutes to execute, since this sequentially opens a list of urls, extracts the html content and saves some information contained therein. Therefore, I scheduled the three jobs in crontab at different times.
Below my crontab

@daily ID=afstoken kinit --renew
0       18      *       *       1-5     /usr/bin/python /home/andrea/Documents/script1.py;

10      18      *       *       1-5     /usr/bin/python /home/andrea/Documents/script2.py;

12      18      *       *       1-5     /usr/bin/python /home/andrea/Documents/script3.py;  

Of these, only the first is executed. As you see, I tried inserting an empty line in between instructions and adding the ; at the end of each, but still the second and third jobs are not executed. Each of the three python scripts is executable.

Does anybody know why this is happening?

Could it be because the environment variables SHELL, PATH and MAILTO are only set in the first job? I can't see how, though, since I thought that setting them at the top of crontab, would set them for all jobs.

Some advice on how to solve this issue would be largely appreciated, since I wanted to add a fourth job to the list. Furthermore, if think there is room for improvement, I would be very happy to learn.
Thank you

  • AFAIK, there is no need of ; at the end. – d a i s y Feb 16 '17 at 8:46
  • even worse: the ; breaks it. The empy lines are meaningless too ;-) "would set them for all jobs. " it does. check /var/log/cron for error notices. There you can see if the scripts are started. I bet they are and something in the scripts is wrong. Them being started and doing what you expect are 2 different things ;-) – Rinzwind Feb 16 '17 at 9:13
  • thanks a lot to both for the reply. actually there is no log in /var/log/cron but I could find it in cat /var/log/syslog instead and, indeed, you are right: the scripts are executed. To check if I was hallucinating, I grouped the last two scripts into one and I added a print instruction, so later today I will check if they are actually working. – andrea Feb 16 '17 at 9:48
  • You can check log with grep CRON /var/log/syslog – d a i s y Feb 16 '17 at 10:06
  • it's a mystery: the script runs correctly if called from the command line and is executed by crontab (there are the executions reports in syslog) but it did not produce the result. AI is taking over... – andrea Feb 16 '17 at 17:55

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Browse other questions tagged or ask your own question.