Creating a boot script in Ubuntu

3

May 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!!! 🙂 🙂 🙂

Advertisements

3 thoughts on “Creating a boot script in Ubuntu

  1. mahendra says:

    this is exciting dude, will definitely follow this one

  2. […] 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 […]

  3. Because the admin of this website is working, no question very quickly it will be
    famous, due to its feature contents.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Milind Padalkar

Milind Padalkar

Blog Stats

  • 55,178 hits

Top rated

Enter your email address to follow this blog and receive notifications of new posts by email.

Join 120 other followers

Add This

Facebook Twitter More...

Flag Counter

free counters

%d bloggers like this: