0

I am using a shell script to execute a series of commends every time I boot my computer.

One of the commands in the script is

sudo insmod blablabla

This command needs to be run as root, so double clicking the .sh file and choosing run is not an option, I have to choose run in terminal, and then enter the password in the terminal.

Is there any way to go around that?

Also, if yes, will it work if I add the script to the startup processes so that I don't have to run it every time?

ppp
  • 2,035
  • 9
  • 32
  • 52

3 Answers3

3

Consider creating a start-up script that runs at boot. man update-rc.d for instructions. Any system start-up scripts run as root.

Another alternative would be to start the script using "cron", using an "@reboot" field. You can man 5 crontab for instructions on how to format your cron tab. Root has a cron tab that runs things as ... root. :)

Note that most of the solutions people provide here will require at least basic knowledge of how to get around on a command line. The idea that you would "double-click a .sh file" is alien (or at least uncommon) to most folks who manage unix and linux systems.

ghoti
  • 45,319
  • 8
  • 65
  • 104
  • 1
    +1 for the comment about double clicking a .sh file. :) But I'm pretty sure Ubuntu is moving away from the old System-V style init scripts, so even though they are still supported, they may be obsolescent. In order to weed out older users like me, they changed to [upstart](http://upstart.ubuntu.com/cookbook/). – Marty Fried Jan 18 '12 at 17:17
  • Thanks for the link to upstart. I do ubuntu things only rarely - most of my time is spent in Debian and FreeBSD. More to learn.... – ghoti Jan 18 '12 at 17:25
  • My unfamiliarity with the stackexchange notifications caused me to see this answer just now. Getting around is alien to me at this point, and since the script gets the job done, I will have to stick with it until I have some free time to experiment and find the correct way to solve the problem. – ppp Jan 27 '12 at 04:24
  • @AnPel, no worries. :) In retrospect, Graham's suggestion of using modprobe is probably the best one you've got here. – ghoti Jan 27 '12 at 04:42
2

Leverage sudoers to run the command as a normal user. Refer to the Ubuntu community wiki on sudoers

Web User
  • 7,438
  • 14
  • 64
  • 92
2

Rather than using insmod, you might want to consider using modprobe instead, for adding modules to your kernel. Among other advantages, modprobe has a configuration file, /etc/modprobe.conf, in which you can specify modules to be loaded at boot. Check out the modprobe.conf man page for further details.

Graham
  • 1,631
  • 14
  • 23