I have a python script that is located at /etc/testscripts/WebServer. I call this usually from the command line by calling sudo python3.6 /etc/testscripts/WebServer.

I have a bash script that looks as follows:


nohup python3.6 /etc/testscripts/WebServer

The name of this bash file is /etc/testscripts/startwebserver.sh.

How can I get this to execute on startup? The unit is running headless so no users are logging in. I did this before by adding sudo python3.6 /etc/testscripts/WebServer to /etc/rc.local but I want to run this via a bash script so that I can modify it later if needed by just changing the bash script rather than modifying rc.local.

I tried adding sudo /etc/testscripts/startwebserver.sh & to rc.local and it didn't work.

Thanks in advance

  • sudo needs an interaction, password... That's why it fails. And sudo isn't needed when running in rc.local. – MatsK Oct 10 '18 at 19:57
  • @MatsK Should I just change it to /etc/testscripts/startwebserver.sh & then in rc.local? Also, is the & needed in rc.local or should I put that in the bash script? Thanks! – Phillip McMullen Oct 10 '18 at 20:05
  • Yes. The trailing & informs the shell to put the process startwebserver.sh in the background. Without the & rc.local will wait for the startwebserver.shto complete before it processes the rest of rc.local. – MatsK Oct 11 '18 at 5:11

I got it working. Here is my setup:


/etc/testscripts/startwebserver.sh &


python3.6 /etc/testscripts/WebServer &
  • Hmmm, to use my comment and the post that as an answer is not encouraging me to assist you in the future. – MatsK Oct 11 '18 at 5:16

You need to remove sudo from rc.local. Sudo needs an interaction, you need to type in the password and that's not possible when the system is booting.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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