0

I'm new to linux, and was told I could use a feature called cron job to run a python script I made execute every 10 minutes. Problem is the the python script isn't running. There doesn't seem to be a clear cut way to know if I've formatted the job correctly, but in any case I've tried a number of paths to no avail.

Because I'm so new I'll show you the steps I took. On my RasPi, I first typed "crontab -e" and get a field like this:

# Edit this file to introduce tasks to be run by cron.
#
# Each task to run has to be defined through a single line
# indicating with different fields when the task will be run
# and what command to run for the task

Skipping more help text

# 0 5 * * 1 tar -zcf /var/backups/home.tgz /home/

# m h  dom mon dow   command

and I add my line at the bottom, without removing the text above.

*/10 * * * * ~/WeatherProject/HOURLY/windDirExtract.py

The above didn't work, and someone else did something similar to this but still no luck.

*/10 * * * * /home/MyName/WeatherProject/HOURLY/windDirExtract.py

and then I tried different permutations but I've got nothing.

*/10 * * * * /home/MyName/WeatherProject/HOURLY python windDirExtract.py
*/10 * * * * /home/MyName/WeatherProject/HOURLY windDirExtract.py

I'll make any edits if I haven't been clear, but first big question is can I even run short little python scripts with Cron Job, or did I just get bad advice?

  • 1
    Is your script marked executable (chmod +x), and does it begin with #!/usr/bin/python? – Patrick Sep 24 '13 at 1:28
  • Check the logs, Redhat:sudo grep CRON /var/log/messages or Debian/Ubuntu: sudo grep CRON /var/log/syslog – slm Sep 24 '13 at 1:30
  • What distro is this on raspi? I'm using OpenELEC and it has /var/log/messages. Also the service cron needs to be running which it isn't on my system. – slm Sep 24 '13 at 1:31
  • If my understanding of what a distro is happens to be correct, I'm running Raspbian. – Monte Carlo Sep 24 '13 at 1:33
  • Do a ps -eaf|grep cron do you get any processes running? – slm Sep 24 '13 at 1:35
5

Make sure your command works from the command line first

/usr/bin/python /home/MyName/WeatherProject/HOURLY/windDirExtract.py

Then try the same in the crontab

*/10 * * * * /usr/bin/python /home/MyName/WeatherProject/HOURLY/windDirExtract.py
1

Your script seems to work fine, running this from cron though will not work as expected. For example:

$ ./windDirExtract.py 

START
2013-09-23 22:32:39.376584
283

Running this script produces the output above. But with cron the output needs to go somewhere. I would suggest writing it out to a file to start, like so via cron:

*/10 * * * * /home/MyName/WeatherProject/HOURLY/windDirExtract.py >> /home/MyName/weather.log

This will capture the output to the log file, weather.log where you can review it to see if the cron is running correctly. Doing the above will continuously append the output every 10 minutes from your script to the log file like this:

START
2013-09-23 22:32:39.376584
283
START
2013-09-23 22:42:39.376584
283
...

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.