Running scripts on startup/shutdown @Ubuntu


As I’m using RxTx libraries for serial communication and I couldn’t handle the locks and permissions on the ports when Tomcat closes( please comment if you know:)), I need to remove locks and give appropriate permissions to ports on startup. Today I saw a post @ and I tried it on my pc. I’m using Ubuntu 11.10.

First write your script and make it executable and move it to /etc/init.d/.

$ chmod +x /home/gokceng/Desktop/

$ sudo cp /home/gokceng/Desktop/ /etc/init.d/

$ sudo update-rc.d start 99 2 3 4 5 .

The parameters on the last line: : your script to run

start : When your script run, it can be  stop

99 : On start in this scenario, it makes your script to run after everything. It could be 1 for being first or anything between 1 and 99.

2 3 4 5 : run levels of your  script

. : Don’t forget to put this 🙂

My script is like that, it is useless but it is only for explanation:

# Provides: myScript
# Required-Start: $remote_fs $syslog
# Required-Stop: $remote_fs $syslog
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Start daemon at boot time
# Description: Enable service provided by daemon.
sudo chmod 666 /home/gokceng/Desktop/myTest

The lines between BEGIN INIT INFO and END INIT INFO is for getting “missing LSB information” error. You can get more information about these lines from

For more compact way of running your script both on startup and shutdown you can also use this:

update-rc.d yourScript start 20 2 3 4 5 . stop 20 0 1 6 .

You can see other usages check this link:

I hope it helps you.


3 thoughts on “Running scripts on startup/shutdown @Ubuntu

  1. Hi! I know this is kinda off topic however I’d figured I’d ask.
    Would you be interested in trading links or maybe guest writing a
    blog article or vice-versa? My blog addresses a lot
    of the same topics as yours and I think we could greatly benefit from each other.

    If you happen to be interested feel free to send me
    an email. I look forward to hearing from you! Awesome blog by the

  2. This is a great tip particularly to those fresh to
    the blogosphere. Brief but very accurate info… Thank you for sharing this one.
    A must read article!

  3. You could certainly see your enthusiasm in the
    article you write. The sector hopes for even more passionate writers such as you who aren’t afraid to say
    how they believe. At all times follow your heart.

Leave a Reply

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

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

Google+ photo

You are commenting using your Google+ 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 )


Connecting to %s