Creating a boot script in Ubuntu
3May 9, 2011 by Milind Padalkar
All the people who wish to run scripts at boot time in Ubuntu, here’s the solution.
I will demonstrate a simple script that will copy the /var/log/syslog file onto my Desktop every time my machine boots. Open the terminal and do the following.
cd ~/Desktop nano cpsyslog
Here I type the following lines. The first line is to copy the syslog file to my Desktop. The second line is to change the ownership of the copied file to user milind and group milind.
cp /var/log/syslog /home/milind/Desktop/syslog chown milind.milind /home/milind/Desktop/syslog
Close the editor and exit.
ctrl+o and enter ctrl+x
With this I have successfully created a script (cpsyslog) to copy the /var/log/syslog file to my Desktop. This file needs to be placed in /etc/init.d/ folder.
sudo cp cpsyslog /etc/init.d/
The copied script needs to be made executable. This can be done as follows.
sudo chmod +x /etc/init.d/cpsyslog
Now update rc.d with default values for the script.
sudo update-rc.d cpsyslog defaults
And you are done. Your script will be executed every time your machine is booted.
What if at some point of time you feel that running the script at boot time is no longer required? You just need to remove the symlink to your script using the following command.
sudo update-rc.d -f cpsyslog remove
Optionally, you may also delete the script from /etc/init.d/ folder it you never want to activate this script in future.
sudo rm /etc/init.d/cpsyslog
And you are done!!! 🙂 🙂 🙂
this is exciting dude, will definitely follow this one
[…] be performed every time the system boots up. This is not much of a problem to tackle if you follow my post to create a boot script in Ubuntu. In that case, the contents of the file having the script will simply be the above line i.e. compiz […]
Because the admin of this website is working, no question very quickly it will be
famous, due to its feature contents.