Just a thought

Adding / Removing Shell scripts (Ubuntu 8.10)

Posted by stringofthoughts on April 16, 2009

I’ve been trying to add a auto mount script to mount all my window drives at startup. After searching for a while and testing few test scripts I finally found out how to add scripts at startup and how to remove scripts.

Adding a script

First of all write a script :), say test.sh and put it in the directory /etc/init.d . Next we need to make it executable so.

$ sudo chmod +x test.sh

You can check if the script is working by issuing

$ sudo ./test.sh

Assuming the script is working as expected, to make the script run at startup / reboot.

$ sudo update-rc.d -f test.sh start 99 2 3 4 5 . // Run at startup

$ sudo update-rc.d -f test.sh start 1 0 6 . // Run at reboot

Just a reminder there is dot (.) at the end of command.  Don’t forget that 🙂 . Now you are done adding a script to run at startup.

Removing a script.

Just a reminder for new users, don’t just go to /etc/init.d and delete the script file 🙂 that wouldn’t help and may cause you trouble. We need a nice little app called rcconf ( Debian runlevel configurtion tool)

$ sudo apt-get install rcconf

then run rcconf (only root can run rcconf)

$ sudo rcconf

rcconf1The inteface is very simple. It lists the scripts so all you need to do is find out where is your script and toggle “*” using space bar  and then select OK. That’s all. The script is now removed but still present in the directory /etc/init.d but you can safely delete it now.

7 Responses to “Adding / Removing Shell scripts (Ubuntu 8.10)”

  1. […] Adding / Removing Shell scripts (Ubuntu 8.10) […]

  2. Darren said

    Thanks for writing this post! I followed your instructions, however, I cannot seem to get a test script to run when I start up Ubuntu 8.10.

    Here is my script:

    #!/bin/sh
    echo hello!
    touch ~/afile

    Which I save in a file fff.sh and make executable using sudo chmod +x fff.sh. I also tested that the script was executable by running sudo ./fff.sh which indeed outputs “hello!” and touches the file “afile” in my home directory.

    I then execute the following update-rc.d command and restart Ubuntu. Alas “~/afile” has not been touched!

    sudo update-rc.d -f fff.sh defaults

    I also tried the run at startup (sudo update-rc.d -f fff.sh start 99 2 3 4 5 .) and “Run at reboot” (sudo update-rc.d -f fff.sh start 1 0 6 .) options, both without any luck.

    Do you have any pointers please?

    • stringofthoughts said

      Hi,

      For running at startup/reboot copy the script file to /etc/init.d

      $ sudo cp fff.sh /etc/init.d

      then switch to directory /etc/init.d and there you ‘ll run

      $ sudo chmod +x fff.sh

      And after this step update runlevel

      $ sudo update-rc.d -f fff.sh start 99 2 3 4 5 .
      $ sudo update-rc.d -f fff.sh start 1 0 6 .

      Let me know if it works. The script files should be in /etc/init.d

  3. Darren said

    Thank you for your help.

    Unfortunately, I still have no luck after following your steps (including placing the scripts in /etc/init.d). I am fairly new to Ubuntu so I am wondering if there is something that is very obvious to an experienced user which I am missing? My thoughts are:

    * Does the script have the correct permissions set to run at start up?
    * Is there a setting in Ubuntu that prevents custom scripts from running at start up?

    I have tried many different runlevels and my script appears in the rcconf tool with an x next to it. I am not sure what to try next actually!

  4. Darren said

    Actually, I managed to get it working by following the Ubuntu help docs:
    https://help.ubuntu.com/community/RcLocalHowto

  5. […] Original Post From:StringOfThoughts […]

  6. WSmart said

    With drives, I add a line to my fstab.

    What I ended up doing for my ROVclock AMD/ATI overclock command-since ROVclock is reset when you reboot-is I made a script and then added it to my System>Preferences>Sessions-startup programs.

    Works great and it couldn’t be simpler. Just open a text editor and add a couple lines, cd and execute, and market it in preferences to execute as program.

    cd /rovclock-0.6e

    sudo ./rovclock -c 482 -m 242

    Thanks all!

    Be real, be sober.

Leave a comment