1

I'm trying to set up a Cron Job on someone else's code to run on an ASUS Tinkerboard

It's currently a simple script that just connects to a device within range (that works)

I've used crontab -e to open up my file, and all I've put in is:

0 * * * * * ~Projects/Tinker/example.py

I want it to run every hour on the hour, but it isn't doing so. I think I'm not setting up my directories correctly. On the command window, the only thing I see for directories is:

name@linaro-alip ~/Projects/Tinker/example.py

How can I fix this so that my program will run every hour?

Shakes
  • 531
  • 1
  • 5
  • 16
RAgarwal
  • 21
  • 3
  • I don't know anything about that environment, but my first suggestion is to use the explicit path to the executable without the tilde. – DrC Jul 03 '18 at 16:34
  • I've got the explicit path and I added it in. still not working – RAgarwal Jul 03 '18 at 17:33
  • The entry of your crontab is missing a slash before "Projects". So it should read ~/Projects.... instead of ~Projects. Just as a tipp - before I add something as a cronjob, I always copy - paste it in the shell and try whether it works beforehand. – Jürgen Gmach Jul 03 '18 at 18:04

1 Answers1

0

Do you have to use Putty? If not, see this answer - How do I get a Cron like scheduler in Python?.

It uses a library called schedule. I'm using it myself to delete files from a directory every morning.

basically you will `pip install schedule', and then run your script with something like:

import schedule 
def job():
    #Whatever the function does

schedule.every().hour.do(job)


while True:
    schedule.run_pending()
    time.sleep(1)

Hope this helps.

PythonParka
  • 134
  • 3
  • 13
  • It does have to be in Putty, I tried what you said and it isn't working. I get the error "schedule is not defined" even after running the install I put import schedule in my script but it says "no module named schedule" – RAgarwal Jul 03 '18 at 17:05
  • After installing "schedule" you have to import it before you use it in the script. – Jürgen Gmach Jul 03 '18 at 17:58
  • Sorry, edited answer to include import statement. It should work now – PythonParka Jul 03 '18 at 19:10