I have a number of sensors connected to my pi 3 and i put the python scripts (7 of them) that starts the sensors at boot in the /etc/profile/ folder.. Of the 7 scripts, i noticed that only the scripts that turns on a led and the 16x2 lcd runs at startup no matter where i put the scripts, (be it rc.local or chrontab) the other scripts that should startup my ldr, mq5, dht11, pir sensors do not run at startup.

I also should not fail to mention that the problem started after i used the "kill all python" command one day. While i was trouble shooting this issue i backed up my sd card and re-flashed an earlier image of my sd card and all the scripts booted with the pi. But the thing is i do not want to have to start my project all over again. How can i force all scripts to startup with my pi?

  • EDITED What i'm saying is that i put 7 python scripts in /etc/profiles/ to run at startup. only 3 of the 7 scripts initiate at startup. I want to know the reason why and how to fix this. I also tried 3 other ways of running a script at startup but only 3 scripts end up starting with the pi. 4 fail to launch.
  • 1
    Although there are substantive differences between this and the duplicate, what they have in common is confusion about what "at boot" is and what /etc/profile is actually for (hint: it is not for running arbitrary programs at boot). You need to get this clear in your head and choose a more appropriate method; what you have here boils down to, "I am doing this the wrong way. Why doesn't it work the way I want?" -> Because you are wasting your time trying to make the wrong way right.
    – goldilocks
    Commented Jan 4, 2018 at 16:41
  • Like I stated in the question, it does not matter where I put the scripts whether crontab or /etc/rc.local, 4 of the scrips that have to do with playing audio never loads. Commented Jan 5, 2018 at 10:57
  • Great, so you are saying no matter what you do it does not work -- then there is no point in asking for yet another way to do it. There is not an infinity of means, and there are means which should work for everything. If the latter does not work, it is because you are doing something wrong. There is no information here that would allow anyone else to tell you what that is. You need to try and do some debugging, e.g, via logging, and possibly using a shell wrapper to check the exit status of the things which supposedly "never load".
    – goldilocks
    Commented Jan 5, 2018 at 11:04

1 Answer 1


To make your python script run at startup, you should write something like this in your rc.local files.

open file editor with your inbuilt software like, nano /etc/rc.local

sudo /root/abc.py (Note: here abc.py file is in root directory).

  • I did that but 4 scripts out of 7 never launch at startup with the rest. Commented Jan 4, 2018 at 15:38
  • sudo in a script is a bad idea since it expects a user interaction, typing in the password!
    – MatsK
    Commented Jan 14, 2018 at 12:37

Not the answer you're looking for? Browse other questions tagged or ask your own question.