1

I have a python script called mediacircus.py that works when run manually (using Idle) in /home/pi. I have a Cron schedule to run it every minute that looks like this:

* * * * * /usr/bin/python /home/pi/mediacircus.py

but a check using

grep cron /var/log/syslog

shows no evidence that it has run, even though another unrelated task that also runs every minute--a shell script--does run. I have ensured that the script is executable using chmod.

Using Idle, I see that /home/pi/ is a valid path.

I've tried replacing "/usr/bin/python" with simply "python", and also taken this part out completely, to no avail.

What am I doing wrong?

10
  • What does 'YA' stand for?
    – Dirk
    Commented Aug 20, 2018 at 20:38
  • What is idle? When I use ~$ idle --version on the command line I get: bash: idle: command not found.
    – Ingo
    Commented Aug 20, 2018 at 22:01
  • @Ingo idle / idle3 is the 'IDE' that comes with most Python installs. en.wikipedia.org/wiki/IDLE
    – Dirk
    Commented Aug 20, 2018 at 22:03
  • @Dirk Ah.. not a command line ;-) Could it be that cron does not find the environment which idle provides?
    – Ingo
    Commented Aug 20, 2018 at 22:26
  • 1
    "YA" stands for "Yet Another"
    – ahclem
    Commented Aug 20, 2018 at 22:58

1 Answer 1

1

idle is likely causing you to believe that your script is executable, when in fact it is not. You can confirm this by starting your script from the command line, just as you do in your crontab; i.e. type this at the command line:

/usr/bin/python /home/pi/mediacircus.py 

Also note that on Raspberry Pi, /usr/bin/python executes Python 2 - not Python 3.

In the event your program throws an error when run under cron, the following may be useful in capturing any error codes:

/usr/bin/python /home/pi/mediacircus.py > ~/cronjoblog 2>&1  

This will redirect the stderr output to a file in your home directory.

And you haven't revealed any of your code, so I'm forced to guess as to whether or not your .py file includes an appropriate shebang in the first line. Try the following:

/usr/bin/python 

Why? cron has a different set of environment variables than you do when you run as pi. In other words, cron's $PATH is different that pi's. Hope this helps.

4
  • Yes, Seamus, it does run from the command line. The shebang looks like this: #!/usr/local/bin
    – ahclem
    Commented Aug 20, 2018 at 22:48
  • @ahclem: See edited answer; it seems you've run into the diff between cron's PATH and user pi's PATH (not the same)
    – Seamus
    Commented Aug 20, 2018 at 23:17
  • Thanks to all who responded; it works now. I changed the shebang to what Seamus suggested. The script gave an error so I had to use absolute addressing of the locations of files. Once that was done, it works as expected.
    – ahclem
    Commented Aug 21, 2018 at 11:32
  • @ahclem: Glad you got it working. Please read this
    – Seamus
    Commented Aug 21, 2018 at 15:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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