3

I’m trying to make a script run twice every hour during business hours on weekdays, and i have the following in my cron setup:

\# m     h       dom     mon     dow     command

8,48    8-17    *       *       1-5      python ~/documents/scripts/script.py

However, nothing is ever performed. I have tried variations on this, but nothing seems to happen at all. running the script manually works fine.

my only other cron script runs like clockwork:

45      5       *       *       *       python ~/documents/scripts/rdiff.py

This one takes a backup of my system to an external disk at 05:45 every morning.

What am I missing?

5
  • Do you have something in your cron log (eg /var/log/cron.log) or in syslog? Aditionnaly, Have you tried writing each hour and day of week, separated by commas instead of dash ?
    – Toine42
    May 25 '15 at 15:43
  • there was no cron.log. in the syslog, there were a number of messages that looked like this: May 25 15:17:01 box CRON[5582]: (root) CMD ( cd / && run-parts --report /etc/cron.hourly) and also some that looked like this: May 25 07:54:25 box anacron[3594]: Normal exit (1 job run) (don't know how to format this better) i will try to format my crontab the way you suggested, and see what happens.
    – memius
    May 25 '15 at 16:12
  • Does your script make use of environmental variables? See this. May 25 '15 at 20:39
  • no environmental variables: i changed it to this: 8,48 12,13,14,15,16,17 * * 5,6,7 echo ding > ~/crontasklogg.txt and there is no change. nothing happens. no dings in the file.
    – memius
    Jun 7 '15 at 14:41
  • I suspect the problem is in the Python script itself, not in your crontab entry. Can you post the content of script.py?
    – Larssend
    Jun 25 '15 at 5:21
3

Your crontab time spec is correct, I just verified it with this:

1,41 0-17 * * 1-5 /bin/echo 'running'

Since your 2nd crontab entry runs fine then python is found with your default environment (it's safer in general to use full path for executables).

Since your script itself runs fine in terminal but not when launched from cron I can only conclude that the issue lies with the difference in environment between your regular interactive session and the non-interactive one that cron provides.

Answers along this line (plenty of them on several SE sites) could help you investigate further: https://serverfault.com/questions/337631/crontab-execution-doesnt-have-the-same-environment-variables-as-executing-user

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.