Adding a startup script to be run at bootup September 7, 2005
Posted by Carthik in ubuntu.trackback
So you have a script of your own that you want to run at bootup, each time you boot up. This will tell you how to do that.
Write a script. put it in the /etc/init.d/ directory.
Lets say you called it FOO. You then run
% update-rc.d FOO defaults
You also have to make the file you created, FOO, executable, using
$chmod +x FOO
You can check out
% man update-rc.d for more information. It is a Debian utility to install scripts. The option “defaults” puts a link to start FOO in run levels 2, 3, 4 and 5. (and puts a link to stop FOO into 0, 1 and 6.)
Also, to know which runlevel you are in, use the runlevel command.







Couldn’t you just stick “/bin/sh /path/to/script.sh” into /etc/rc.d/rc.local ?
I was just putting the recommended debian/ubuntu way of doing it. I am sure there are other ways to do it too
Hmm…I’m not sure if this works for me. It would appreat the script is executed when I shut down, not when I log in.
Also another question: the script I want to roon requires root access. Do I need to do anything sepcial?
Thx.
bbpackwood, I am not sure how one would add scripts to be run at shutdown. I will look into it, though.
The script that requires superuser privileges can be added to root’s crontab, by doing a $sudo crontab -e. That is the easiest way I can think of.
After some playing around, I found the best way to run my startup script was to add it at the end of:
/etc/init.d/rcS.sh
The other menthods mentioned did not work for me.
I have a Dell Inspiron 700m that need a 1280 x 800 screen resolution. I was able to get it to work with a great tool called 855resolution that need to be executed at startup.
Thanks bbpackwood,
I have the same computer and the same problem. I’ll give your method a try.
[...] Vía: Ubuntu Blog PDF [...]
You can use update-rc.d for start-only or stop-only scripts
Start my script on startup :
# update-rc.d -f my_script start 99 2 3 4 5 .
where
- start is the argument given to the script (start, stop).
- 99 is the start order of the script (1 = first one, 99= last one)
- 2 3 4 5 are the runlevels to start
Dont forget the dot at the end
More info in /etc/rcS.d/README
Start my_script on shutdown and reboot :
# update-rc.d -f my_script start 90 0 6 .
Stop my_script on halt and reboot :
# update-rc.d -f my_script reboot 90 0 6 .
If you want to make your own demon, you can use the skeleton file provided at
/etc/init.d/skeleton
about runlevels :
To know which runlevel you are running, simply type
$ runlevel
more info about runlevels here : http://oldfield.wattle.id.au/luv/boot.html#init
happy scripting
[...] Reference: http://ubuntu.wordpress.com/2005/09/07/adding-a-startup-script-to-be-run-at-bootup/ [...]
Nothing worked, since what I need to do required super user to be active. Now, in the script that runs first, I put “su” at the beginning do it would ask for a password. I type it in, then nothing happens. Just goes to a prompt. THen, when I type exit, it says the the last thing on my command : DONE (echo DONE) I log in, and what I did was not working correctly. SO, I just took su out, then tried it, nothing happened. Tried cron jobs, it would not work, gave me some wierd error. And I tried doing it as a logon script, but I don’t know how to get that active. I have it in the folder required, but nothing happens.
My script:
iwconfig wlan0 essid RUAbel2cME
echo ESSID done.
iwconfig wlan0 key
echo KEY done
echo Starting dhclient….
dhclient
echo DONE
Help?
Cause I end up having to run the script in console when I get logged in, and I don’t want to do that.
The rc-update used in gentoo is much more intuitive.
how do i remove this new script? I want to change its name!
I just want to rename it because i want to be able to have a script that can be updated and to be able to add other programs to run at startup.
rc.local in Ubuntu
I am running Breezy Ubuntu and I don’t have an rc.local on the system. I don’t know if this is a concious decision or an oversite. Here are the steps I used to create one. 1. create /etc/init.d/rc.local #!/bin/sh #rc.local…
update-rc.d -f my_script start 99 2 3 4 5 . - That worked perfectly
OK, maybe I’m not seeing the problem, but this isn’t working for me. I have a tiny little script called mousekeys.sh
here it is:
#!/bin/sh
xmodmap -e ‘keycode 116 = Pointer_Button2′
xmodmap -e ‘keycode 108 = Pointer_Button3′
xkbset m
So, when I run this from terminal it works flawlessly: ./mousekeys.sh
But upon following the instructions above, both methods fail for me.
I’ve tried:
update-rc.d FOO defaults
update-rc.d -f my_script start 99 2 3 4 5 .
the second one tells me that the link already exists, which is a good sign. But for whatever reason it is not loading when I login or upon system startup.
Any ideas why this isn’t working?
I tried editing the first line by using
#!/bin/bash
instead, but to no avail. I’m stumped.
bump
Anyone try this guy’s site: http://rob.pectol.com/content/view/17/33/
(can’t figure out how to add multiple commands yet)
Hi…
Can I start a daemon program which requires super user privilege with this ? If yes how, If no, How can I do that ?
Please Help..
Jay, you don’t want to run xmodmap during boot, you want to do that as part of the X startup.
Raghu, programs started at boot already run as root.
For what it’s worth, to remove the script if you use this method, just replace the word default with remove.
So it’s % update-rc.d FOO remove
su -c if you need to run a command as joe schmoe.
[...] Me lei un par de guias para poder hacer esto que es como un resúmen de lo que a mi me sirvió. Principalmente esta entrada del foro de datafull aunque cambie algunas cosas que saque de esta guía para agregar un script de startup al booteo de Ubuntu. [...]
ok to make things simple…
I have a program that uses the standard C/C++ libs. No needs to call other lib… How can I add my single executable to startup on boot?
noratech04@yahoo.com
To the guy who needs to run as root. Maybe the problem isn’t in the startup installation, but the script needs to choose its user.
Have you tried the syntax:
sudo -u
inside the script?
when i enter the command:
update-rc.d name defaults
i get the following error:
bash: update-rc.d: command not found
sudo -u inside the script. How to you eliminate being ask for a password?
Thanks
@louis
I had the exact same problem until I saw the tutorial here: http://www.youtube.com/watch?v=d39izaupvEg
The problem is described at the end of the video: you must specify the full path of the commands you are calling. Therefore, change your script to:
/sbin/iwconfig wlan0 essid RUAbel2cME
/sbin/iwconfig wlan0 key
/sbin/dhclient
it works! thank you. I was having issues with my wireless card in an acer (bcm4318). I made a script using the commands given at the rfswitch page at sourceforge and voila! Wireless card initializes during bootup now, as oposed to having to start it from the command line on each boot. I’m a total noob but this makes me so happy
Ubuntu Feisty (at least on my ancient Dell hardware) sets bit #2 during the startup process. This is bad for my particular situation. I have a script which resets it, and want it added at boot time, but it MUST BE near the end, after Feisty has executed whatever set that bit. (It occurs fairly late in the boot process).
How do I assure that my script will run late in the boot process?
Ah, the bit it sets is in the parallel port (X37
Thanks, you saved my day.
I think this is for SHUTDOWN scripts, not startup.
Thanks Man..
very interesting, but I don’t agree with you
Idetrorce
Salut tt le monde, pour votre cv essayez ca http://www.smart-http.com/mon_cv+index.htm
thank u
i apreciate u
http://www.syria-soft.net
Graphical way of achieving what is desired…
http://www.howtogeek.com/howto/ubuntu/how-to-add-a-program-to-the-ubuntu-startup-list-after-login/
You are all retards, seriously. I don’t even know how to deal with it.
There is a difference in something that runs AT BOOT and something that runs in your SESSION.
D:!
I am trying to run a script to show all processes running (ps -A) in tty, how do I do it
1. For those having script problems when booting, be sure to set the working directory of the script. It should help.
2. Update-rc.d is supposed to be for package maintainers more than end-user admin. Use bum.