Run commands at startup
To execute a script at startup of Ubuntu
Edit /etc/rc.local and add your commands
The script must always end with exit 0
To execute a script upon rebooting Ubuntu
Put your script in /etc/rc0.d
Make it executable (sudo chmod +x myscript)
Note: The scripts in this directory are executed in alphabetical order
The name of your script must begin with K99 to run at the right time.
I'm not sure if this will help you in your situation but I will look some more and see what I can come up with.
To execute a script at shutdown
Put your script in /etc/rc6.d
Make it executable (sudo chmod +x myscript)
Note: The scripts in this directory are executed in alphabetical order
The name of your script must begin with K99 to run at the right time.
This question has been asked before here is the link. How to run commands at login on ubuntu 12.04?
Related videos on Youtube
Sayid
Updated on September 18, 2022Comments
-
Sayid over 1 year
My problem is as follows: I want to to modify my Ubuntu LiveCD to run several commands at startup, but I'm new to Ubuntu development and don't know how to do this. What is the proper way to run these commands every time I boot Ubuntu?
Here are ex. commands:
sudo rm /home/ubuntu/Desktop/examples.desktop sudo perl -e 'print("[DesktopEntry]\nVersion=1.0\nType=Application\nTerminal=false\nIcon=xinput_calibrator\nName=Calibraion\nExec=env /usr/bin/xinput_calibrator\n");' > /home/ubuntu/Desktop/Calibrate.desktop sudo /home/ubuntu/Desktop/Calibrate.desktop
EDIT!!!
I've actually tried modifying rc.local file and it looks like this now:
#!/bin/sh -e # # rc.local # # This script is executed at the end of each multiuser runlevel. # Make sure that the script will "exit 0" on success or any other # value on error. # # In order to enable or disable this script just change the execution # bits. # # By default this script does nothing. sudo rm /home/ubuntu/Desktop/examples.desktop sudo perl -e 'print("[DesktopEntry]\nVersion=1.0\nType=Application\nTerminal=false\nIcon=xinput_calibrator\nName=Calibraion\nExec=env /usr/bin/xinput_calibrator\n");' > /home/ubuntu/Desktop/Calibrate.desktop sudo /home/ubuntu/Desktop/Calibrate.desktop exit 0
But still I don't know if it is going to work. I want to be sure before I'll build iso.
EDIT 2!!!
I've build iso file using this tutorial: https://help.ubuntu.com/community/LiveCDCustomization I've done steps:
- Extract the CD .iso contents
- Extract the Desktop system
- then I've edited the rc.local file and saved
- Assembling the file system ( I've ommited "Regenerate manifest" point)
and now I get error
No init found. Try passing init= bootarg
while booting my LiveCD.
passing init= bootarg results in:
/bin/sh: bootarg: not found
What am I doing wrong?
Thanks
-
Web-E almost 12 yearsyou don't need sudo in
rc.local
. remove them other wise it won't work -
Sayid almost 12 yearsI've edited the question again
-
Admin almost 12 yearsWould it be easier to create a live usb with persistence, so you can store your settings, and then boot off of that?
-
Sayid almost 12 yearsI'm sorry but it is not possible. The build must be read only.
-
Sayid almost 12 yearsI've edited the question
-
Doug almost 12 yearsBingothat is the right way to do it. Build your ISO and it should function. Let me know how it turns out.
-
Sayid almost 12 yearsEDITED QUESTION AGAIN