-1

I'm trying to start a python script using crontab that runs in the background. I want to restart it every few hours, but for now I'm trying to test it every minute to make sure the crontab is working. The problem is that the python script seems to start and then end a few seconds later.

I can see all the processes using ps aux | grep "python", and that's how I can tell it ends immediately.

Here's my crontab:

* * * * * python /home/alice/wmata/driver.py &

The python script drives an LED matrix, but if I use nohup to start it, it eventually stops several hours later and I can't manually restart it every time. Eventually I also need to run this script with sudo, but for now I'm just trying to get it working without.

Any help would be appreciated, thank you!

EDIT: syslog looks ok

Jan 18 17:54:01 raspberrypi CRON[4464]: (alice) CMD (python /home/alice/wmata/driver.py &)
Jan 18 17:55:01 raspberrypi CRON[4472]: (alice) CMD (python /home/alice/wmata/driver.py &)
Jan 18 17:56:01 raspberrypi CRON[4479]: (alice) CMD (python /home/alice/wmata/driver.py &)
Jan 18 17:57:01 raspberrypi CRON[4490]: (alice) CMD (python /home/alice/wmata/driver.py &)
Jan 18 17:57:04 raspberrypi kernel: [ 5392.686124] hwmon hwmon1: Undervoltage detected!
Jan 18 17:57:08 raspberrypi kernel: [ 5396.845999] hwmon hwmon1: Voltage normalised
Jan 18 17:57:21 raspberrypi kernel: [ 5409.895883] usb 1-1.4: USB disconnect, device number 5
Jan 18 17:57:21 raspberrypi kernel: [ 5409.895909] usb 1-1.4.2: USB disconnect, device number 6
Jan 18 17:57:22 raspberrypi thd[468]: Error reading device '/dev/input/event4'
Jan 18 17:57:22 raspberrypi thd[468]: Error reading device '/dev/input/event5'
Jan 18 17:58:01 raspberrypi CRON[4507]: (alice) CMD (python /home/alice/wmata/driver.py &)
Jan 18 17:59:01 raspberrypi CRON[4514]: (alice) CMD (python /home/alice/wmata/driver.py &)
Jan 18 18:00:01 raspberrypi CRON[4522]: (alice) CMD (python /home/alice/wmata/driver.py &)
Jan 18 18:01:01 raspberrypi CRON[4529]: (alice) CMD (python /home/alice/wmata/driver.py &)
Jan 18 18:02:01 raspberrypi CRON[4536]: (alice) CMD (python /home/alice/wmata/driver.py &)
Jan 18 18:03:01 raspberrypi CRON[4546]: (alice) CMD (python /home/alice/wmata/driver.py &)
Jan 18 18:04:01 raspberrypi CRON[4554]: (alice) CMD (python /home/alice/wmata/driver.py &)
Jan 18 18:05:01 raspberrypi CRON[4561]: (alice) CMD (python /home/alice/wmata/driver.py &)
Jan 18 18:06:01 raspberrypi CRON[4568]: (alice) CMD (python /home/alice/wmata/driver.py &)
Jan 18 18:07:01 raspberrypi CRON[4576]: (alice) CMD (python /home/alice/wmata/driver.py &)
Jan 18 18:08:02 raspberrypi CRON[4586]: (alice) CMD (python /home/alice/wmata/driver.py &)
Jan 18 18:09:01 raspberrypi CRON[4593]: (alice) CMD (python /home/alice/wmata/driver.py &)
Jan 18 18:10:01 raspberrypi CRON[4601]: (alice) CMD (python /home/alice/wmata/driver.py &)
Jan 18 18:11:01 raspberrypi CRON[4608]: (alice) CMD (python /home/alice/wmata/driver.py &)
Jan 18 18:12:01 raspberrypi CRON[4615]: (alice) CMD (python /home/alice/wmata/driver.py &)
Jan 18 18:13:01 raspberrypi CRON[4622]: (alice) CMD (python /home/alice/wmata/driver.py &)
Jan 18 18:14:01 raspberrypi CRON[4631]: (alice) CMD (python /home/alice/wmata/driver.py &)
Jan 18 18:15:01 raspberrypi CRON[4638]: (alice) CMD (python /home/alice/wmata/driver.py &)
Jan 18 18:16:01 raspberrypi CRON[4647]: (alice) CMD (python /home/alice/wmata/driver.py &)
Jan 18 18:17:01 raspberrypi CRON[4655]: (alice) CMD (python /home/alice/wmata/driver.py &)
Jan 18 18:17:01 raspberrypi CRON[4656]: (root) CMD (   cd / && run-parts --report /etc/cron.hourly)

1 Answer 1

0

I figured it out, answering here in case other folks have a similar issue. My script has a relative path coded for a file it reads from (probably bad practice), so when cron was running the file outside that exact directory (/home/alice/wmata), python was throwing an error that it couldn't find the file. I found this error that python was throwing by installing an MTA and examining the mail log under /var/ for my username. I fixed the problem by running cd before my script command (I will later fix my script and remove this):

cd /home/alice/wmata && python /home/alice/wmata/driver.py I later made edits to include sudo and @reboot and an auto-reboot every 6 hours, but I won't go into that here.

1
  • you can accept your own answer
    – jsotola
    Jan 21 at 17:29

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.