Dawoud
Posts: 1
Joined: Fri May 26, 2023 3:27 am

Python at startup not working

Fri May 26, 2023 3:33 am

I'm trying to set my raspberry pis to work at startup. I did the following

Code: Select all

[sudo crontab -e
@reboot python filepath]

and then I configured my raspberry pi to reboot without desktop, the problem is some of 2 my raspberries worked with this method, but three are not working. What could be the problem in this case. Note that if I shifted the SD card from the working ones to the non-working ones. The nonworking would work perfectly so I'm not getting why this is happening.

ghp
Posts: 3251
Joined: Wed Jun 12, 2013 12:41 pm
Location: Stuttgart Germany

Re: Python at startup not working

Fri May 26, 2023 5:53 am

Note that if I shifted the SD card from the working ones to the non-working ones.
The nonworking would work perfectly so I'm not getting why this is happening.
Most possibly the problem on the nonworking SD card is a missing file or perhaps a forgotten crontab entry or perhaps a typo in crontab entry. Or file permissions. Or file a name typo.
Compare the settings between one of your working samples and the nonworking sample.

MiscBits
Posts: 1591
Joined: Wed Jan 27, 2021 12:48 pm

Re: Python at startup not working

Fri May 26, 2023 9:53 am

First thing to do is to record any errors to help work out why it's not working.

e.g.:

Code: Select all

@reboot python filepath 2>> /home/pi/reboot.log
Have a look at the cron and boot pdfs at https://github.com/thagrol/Guides - specifically the troubleshooting sections and use of the redirect options in Linux.

It is also handy to read up on redirecting STDOUT and STDERR to file - Digital Ocean has a guide here but this one of many.

Please understand that by running the job under the root cron (you used sudo to edit) the path and security for this command will be different to your standard user - some programs will be 'missing' as they are not on the path and everything is open - not good for security. The root user (and sudo / su) should only be used when there is NO OTHER WAY to achieve your needs and then only with extreme care.

edit: Forgot to add example redirect and note on sudo ... :oops:

User avatar
thagrol
Posts: 9250
Joined: Fri Jan 13, 2012 4:41 pm
Location: Darkest Somerset, UK

Re: Python at startup not working

Fri May 26, 2023 11:00 am

Dawoud wrote:
Fri May 26, 2023 3:33 am
I'm trying to set my raspberry pis to work at startup. I did the following

Code: Select all

sudo crontab -e
@reboot python filepath
and then I configured my raspberry pi to reboot without desktop, the problem is some of 2 my raspberries worked with this method, but three are not working. What could be the problem in this case. Note that if I shifted the SD card from the working ones to the non-working ones. The nonworking would work perfectly so I'm not getting why this is happening.
The obvious conclusion is that the OS installation and configuration on the SD cards is not identical. It's impossible to say in what way though given how little information you have provided.

As with anny troubleshooting, the first step is to find the error...
Knowledge, skills, & experience have value. If you expect to profit from someone's you should expect to pay for them.

All advice given is based on my experience. it worked for me, it may not work for you.
Need help? https://github.com/thagrol/Guides

Return to “Troubleshooting”