1

I am attempting to run a scheduled .py file every 5 minutes with crontab but I don't think it's working.

I'm following this post with the instructions: Can't run python script from cron

I opened up terminal and ran crontab -e, adding in:

5 * * * * /usr/bin/python /home/pi/Desktop/BacTest/test3.py

to the crontab file.

I then saved the crontab with Ctrl-X, then Y, then ENTER.

Nothing appears to happen, even after a reboot... There is a SQLite database file that the test3.py file is supposed to update, but I don't see the updates happening. At least when I right click on the .py file and .db to view the properties there isn't any change to the last access/modification/permission change, or size of the SQLite .db file. However, if I open up terminal in the /home/pi/Desktop/BacTest and run the test3.py file it all works fine...

Any tips are greatly appreciated!

EDIT This is the test3.py file where I am using a python package called BAC0 to access a building automation system. Its really pretty simple where I can retrieve 2 data points (gas usage & outdoor temp) from the hot water system and save to SQLite on pi. BAC0 has a .save() that defaults to SQLite. In terminal on pi when I run the test3.py file it works just fine...

import BAC0
import pandas as pd

bacnet = BAC0.connect(ip='10.30.4.104/16')
hws = BAC0.device('100:99', 30099, bacnet, poll=0)

hws['THERM'].poll()
hws['OA-T'].poll()


print(hws['OA-T'], hws['THERM'])

hws.save()
bbartling
  • 237
  • 1
  • 12

2 Answers2

0

Using:

crontab -e

This works for me:

0 4 * * * sudo /sbin/shutdown -r now    # Reboot everynight at 0400

00,30 06-23 * * * sudo /home/pi/python/scripts/router/DD-WRT_UpgradeCheck.py
Magwich
  • 116
  • 3
  • Gosh still not working on my end... Do you think it has anything to do with the script? But it works just fine if I open up in terminal /home/pi/Desktop/newBAC0 , and run python test.py – bbartling Sep 26 '18 at 13:50
  • On my crontab program, its just 15 * * * * sudo /home/pi/Desktop/newBAC0/test.py and I used the crontab -e like you recommended and i know it saved properly.. Any tips help! Thank you – bbartling Sep 26 '18 at 13:51
  • One other thought that ran across my head, is I recently installed berry conda which is Python 3.6 but I think Python 3.5 is still installed on the pi. Would it be possible that 3.5 is running when crontab executes? I dont have the specific packages installed on 3.5 if it is even on the pi... Any idea on how to confirm? – bbartling Sep 27 '18 at 18:01
  • I think that the different version issue is quite a possibility. Try writing a simple python script that will write the version of Python is using to a file so you will know which version it is using. Or add those packages to 3.5 You might also use Python's "try" & "except" methods to write the error message to a file. That could be quite helpful. – Magwich Sep 28 '18 at 01:25
0

It is possible that the problem lies in the way to call the editor.

If what you want to change is the crontab root, you must edit it with

sudo crontab -e

and with:

crontab -e

the user's

Ghanima
  • 15,855
  • 15
  • 61
  • 119
quito127
  • 69
  • 1
  • 3