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.
-
in your system settings, there should be a setting for declaring programs to run at start – ravery Jul 04 '17 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? – Jacob Vlijm Jul 04 '17 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. – Schezan Mansuri Jul 04 '17 at 20:57
-
Ah, censorship now too. Excellent. – Lightness Races in Orbit Jul 07 '17 at 17:34
2 Answers
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
Click on Add
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
I suggest using rc.local
to run your commands at the startup (boot time).
First
cd
into the commands directory:cd /path/to/commands
Then make them executable (
*.py
means all files with thepy
extension):chmod +x *.py
You can run the command one by one on all files too:
chmod +x command1 command2 cmd3
Open
/etc/rc.local
file using an editor you like:sudo nano /etc/rc.local
Addd the commands like:
./path/to/commands/command1 ./path/to/commands/command2 ...
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.

- 55,668
- 25
- 164
- 183
-
1It is hihgly unlikely that OP actually means Startup. Most likely the commands should run on log in. – Jacob Vlijm Jul 04 '17 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 04 '17 at 19:38
-
-
-
-
-
I'm able to add those in startup now, but the problem is that the wifi isn't turned on before the command runs, I need my system connected to the internet before executing it. I'm trying to search for a workaround. – Schezan Mansuri Jul 04 '17 at 21:02