how do I get a script to run on boot every time with Linux? (Need this for my daughters birthday gift)

How It Works

Get an answer in three easy steps. Here's how it works...

Ask Your Question

1. Ask Your Question

Enter your programming question at the top of this page and click Get An Answer.

Pick Your Priority

2. Pick Your Priority

Tell us how quickly you want your programming question answered.

Get An Answer

3. Get An Answer

Connect with your programmer via online chat or telephone call.

Answer

Customer

how do I get a script to run on boot every time with Linux? (Need this for my daughters birthday gift)

Last updated
Charles Totherow
Programmer

Hello and welcome to ExpertHelp.com! My name is Charles Totherow and I'm going to do everything in my power to answer your question to your full satisfaction!

I’m available to chat now. Please let me know that you are ready by posting a response. I’ll leave my chat session open for the next 15 minutes or so and wait for your reply. If I don’t catch you this time, please respond with a few times (including your timezone) that work best for you and we can connect then.

Last updated
Charles Totherow
Programmer
2

There are many ways to do this (depending on which distribution of linux you are using there are different tools that are offered).

The easiest way is simply adding the script to /etc/init.d and then running the command

chmod +x go.py
update-rc.d go.py defaults

If you already set up the service, you may also do so via the chkconfig command (that is if the command is available).

In that case, this command should work:

Posted
Charles Totherow
Programmer
chkconfig --level 35 go.py on
Posted
Charles Totherow
Programmer

There are many ways to do this (depending on which distribution of linux you are using there are different tools that are offered).

The easiest way is simply adding the script to /etc/init.d and then running the command

chmod +x go.py
update-rc.d go.py defaults

If you already set up the service, you may also do so via the chkconfig command (that is if the command is available).

In that case, this command should work:

chkconfig --level 35 go.py on
Posted
Customer

Ok, im using raspian on a pi3.  Sorry im really new to programming.  This is the script i want to run https://github.com/arpitjindal97/raspbian-recipes/blob/master/wifi-to-eth-route.sh .  I have saved it to a folder on my desktop.  Should i run the script then input those commands you just sent?

 

Posted
Charles Totherow
Programmer

Yes please run the script first 

Posted
Customer

I ran the script.  Also I got a permission denied when I tried to copy the txt file I have it save in, to the /etc/init.d using the GUi

Posted
Charles Totherow
Programmer

One moment please

Posted
Charles Totherow
Programmer

Can you try to input the commands first, then the script

Posted
Customer

chmod: cannot access 'go.py'': No such file or directory

 

Posted
Charles Totherow
Programmer

One moment please

Posted
Charles Totherow
Programmer

Please try this:

  1. Create a file for your startup script and write your script in the file:

    $ sudo nano /etc/init.d/superscript
    
  2. Save and exit: Ctrl+XYEnter

  3. Make the script executable:

    $ sudo chmod 755 /etc/init.d/superscript
    
  4. Register script to be run at startup:

    $ sudo update-rc.d superscript defaults
Posted
Charles Totherow
Programmer

If you want a script to run when you boot into the LXDE environment:  

  1. Navigate to ~/.config/lxsession/LXDE-pi

  2. Open the autostart file in that folder:

    $ sudo nano autostart
    
  3. Add @midori on a new line. If you want to run something like a python script, put something like @python mypython.py on a new line. Running a script file would be @./superscript, but for some reason the script runs in an infinite loop (perhaps this will stop that).

  4. Save and exit: Ctrl+XYEnter

  5. Restart your Raspberry Pi into the LXDE environment.

Posted
Customer

I think that did it give me a couple of mins to verify

Posted
Charles Totherow
Programmer

I will be here please take your time

Posted
Charles Totherow
Programmer

Was I able to resolve your question today?

Posted
Charles Totherow
Programmer

Are you still with me in the chat?

Posted
Customer

sorry, it did save to the /etc/init.d folder and it did make it executable.  but it seems the script no longer works... 

Posted
Charles Totherow
Programmer

Please try this:

  1. Create a startup shell script in your root directory :

sudo leafpad launch.sh

  1. Save the file
  2. Edit the LXDE-pi autostart file

sudo leafpad /home/pi/.config/lxsession/LXDE-pi/autostart

  1. Add this to the bottom of that file

./launch.sh

  1. reboot
Posted
Customer

still no joy, is it possible the superscript we created is causing and issue.  If so how can i delete it from the init.d folder?

Posted
Charles Totherow
Programmer

There are a couple ways. If you just want to do this temporarily, you can remove the execute bit from the file:

$ chmod -x /etc/init.d/varnish
Posted
Charles Totherow
Programmer

Then re-add it when appropriate:

$ chmod +x /etc/init.d/varnish
Posted
Charles Totherow
Programmer

I apologize I haven’t be able to offer you the most helpful support on this issue. I have requested another Expert to step in and continue assisting you on your (product issue/question). I appreciate your patience while your new Expert prepares to assist you. When your newly assigned Expert is ready, you will be notified via email and you can continue support for your issue. You may also leave this chat page open and check for your new Experts messages

Posted
Customer

thanks,

have a good night

Posted
Customer

figured it out,

"sudo nano /etc/xdg/lxsession/LXDE-pi/autostart" then in that directory type "sudo bash" followed by a space then the address of the script in this case " /home/pi/Desktop/wif-to-eth-route.sh" . Cntrl X to exit "y" to save then "enter".  Reboot and it works great for me.

 

Posted
Charles Totherow
Programmer

I am very happy to hear that.  Would there be anything else I can help you with?

Posted
Customer

Negative, Cheers!

Posted
Charles Totherow
Programmer

Dear Jeffery, It was a pleasure helping you with your programming issue today. Here is a summary of the resolution.


Issue identified : Csutomer needed coding for pi3 device


Solution Implemented : I left replies with code to use at the boot of linux.

Problem solved.


If issue resurfaces in next 30 days, come back to this Question page and let me know. If you are unable to find your way back to this Question page, please contact our customer support either by email (s**[email protected]) OR call us at ***-***-****

Posted

quoteTestimonialsquote

About ExpertHelp

ExpertHelp is changing the way you connect with service professionals.

Whether you have a quick question while preparing your taxes, troubleshooting a computer problem, or need to hire an attorney, ExpertHelp is the most convenient and affordable way to connect with the right service professional to get the job done.

ExpertHelp has been in business since 2011, is an A+ Rated Better Business Bureau accredited member, and offers a 100% satisfaction guarantee on every question you ask!

More Programming Questions...

Ask Your Programming Question & Get An Answer Now!