Read the statement by Michael Teeuw here.
[Solved]How to start a python script @reboot?
-
Hi guys.
i have a python script for my PIR-Sensor to turn on/ off my monitor. But i dont get this one started on reboot. how can i do this?
i know there exists a pir-module, but this one i didnt get running yet.i need your help! :)
thanks so far -
https://github.com/paviro/MMM-PIR-Sensor
It’s a module… not sure how to use it but there you go :) Read the docs should tell you how
-
It is the module I mentioned. Yesterday I thought I can not set this module up. But now it seems working.
-
It does not work at all. At least not the way i hoped.
see here: https://forum.magicmirror.builders/topic/2468/mmm-pir-sensor-delay
so i really like to get the python-autostart working. any help?
-
Look into cron.
[Cron](https://thepihut.com/blogs/raspberry-pi-tutorials/34930820-running-things-regularly-cron -
thanks so far.
i have already put this as cron: @reboot sudo /usr/bin/python /home/pi/monitor.py &
but nothing happenswhen i want to start this, i will get this message:
/etc/init.d/cron restart
[…] Restarting cron (via systemctl): cron.serviceFailed to restart cron.service: Access denied
failed!
So what can i do now? -
@pauabaer It’s easier to just make your python code executable. Then you can just start it with cron with
@reboot /home/pi/monitor.py -
Two questions:
- how do i make it executable?
- when the script is executable, the problem with the failure is still existing, isn’t it?
-
@pauabaer To make the code executable:
- Add #!/usr/bin/python3 to the top of your code.(1st line)
- open terminal and type sudo chmod +x /home/pi/monitor.py (this will make your code executable. You can check that it’s executable by typing “./monitor.py” You code should run.
Then you can add the line @reboot /home/pi/monitor.py to the crontab.
-
Ok. Thanks. I made these two steps and i can see via htop that the script is running.
Hello! It looks like you're interested in this conversation, but you don't have an account yet.
Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.
With your input, this post could be even better 💗
Register Login