User-defined tasks can be done by executing a script at startup and shutdown for Linux. To execute script at startup of Ubuntu, the rc.local can be modified to include additional commands. To execute script when rebooting Ubuntu, the script has to be copied to the relevant directory. Once the permissions of the script have been changed to executable, it will run when rebooting the Linux operating system. Scripts are run in the alphabetical order in the directories and the scripts should be named following the nomenclature rules when executing a script at startup and shutdown.
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.
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.
How to put script in rc*.d?
- Create a script and make it executable
- Copy it to /etc/init.d folder
- Run the command ( dont forget the dot in the end)
sudo update-rc.d script_name start 3 0 6 .
The above command will run the script during shutdown or reboot. update-rc.d adds this script to runlevels rc0.d and rc6.d
rc0.d is shutdown
rc6.d is reboot
source : http://ubuntuforums.org/showthread.php?p=6234799
No comments:
Post a Comment