0

I have some python commands that I want to run at startup, what I need to do everytime I boot my machine is manually start them by changing directories and executing them. Is it possible to make an exectable file which will execute a list of commands in the terminal? Or is it possible to let those command run at the startup ? It will be very handy to make those run by a simple double click instead of manually doing that.

4
  • in your system settings, there should be a setting for declaring programs to run at start
    – ravery
    Jul 4, 2017 at 17:56
  • Please clarify what commands you need to run, to do what. Furthermore, do they need to run from their directory? Do you need them to run in terminal? Also, It seems you need to run them on log in rather than startup, right? Jul 4, 2017 at 19:36
  • @JacobVlijm the commands I use to run are pythonfiles, which help me run a bot, python3 botname.py What I need to do is, make them run as soon as I'm logged in or as soon as the System boots, maybe I got confused between the two, using the solution ravexina provided, I'm able to add those on startup, but the bot doesn't run the way it should as the wifi isn't turned on, I'm not sure what to do to make it run the way I want. Jul 4, 2017 at 20:57
  • Ah, censorship now too. Excellent. Jul 7, 2017 at 17:34

2 Answers 2

0

I suggest using rc.local to run your commands at the startup (boot time).

  1. First cd into the commands directory:

    cd /path/to/commands
    
  2. Then make them executable (*.py means all files with the py extension):

    chmod +x *.py
    
    • You can run the command one by one on all files too:

      chmod +x command1 command2 cmd3
      
  3. Open /etc/rc.local file using an editor you like:

    sudo nano /etc/rc.local
    
  4. Addd the commands like:

     ./path/to/commands/command1
     ./path/to/commands/command2
     ...
    
  5. Save the file and make sure rc.local itself is executable:

     test -x /etc/rc.local || sudo chmod +x /etc/rc.local 
    

You are done, in each boot your commands get executed.

8
  • 1
    It is hihgly unlikely that OP actually means Startup. Most likely the commands should run on log in. Jul 4, 2017 at 19:34
  • 2
  • @steeldriver I really can't remember that the service was enabled or not on my 16.04 :D thanks for pointing it out...
    – Ravexina
    Jul 4, 2017 at 19:38
  • @JacobVlijm I just leave it here as an alternative ;)
    – Ravexina
    Jul 4, 2017 at 19:39
  • This doesn't work :( yes my files are executable. Jul 4, 2017 at 20:50
0

First you need to make the file executable using cmd chmod +x filename.py as your say it is a python file.

After press start button or open Ubuntu dash and search StartUp

Startup Luncher

Click on Add

Menu list in Startup

You will able to see as above now enter name of command and provide path of file, if you want can add some comment. now click on add, your program will run on startup

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .