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
  • 2
  • 14

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
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,958
  • 17
  • 65
  • 125
quito127
  • 79
  • 1
  • 3