How does one have a "terminal" command run automatically at start-up?

Asked by ernie

Being relatively new to Linux, is there a relatively easy way to have the following commands run automatically at start-up?

sudo -s (followed by password), and
echo "base=0xb0000000 size=0x10000000 type=write-combining" >| /proc/mtrr

This seems to prevent Ubuntu from freezing/crashing when streaming or playing media on my Toshiba laptop (running Ubuntu 9.04).

Thanks in advance.

Question information

Language:
English Edit question
Status:
Solved
For:
Ubuntu Edit question
Assignee:
No assignee Edit question
Solved by:
ernie
Solved:
Last query:
Last reply:
Revision history for this message
Monkey (monkey-libre) said :
#1

You have to go: System > preferences > applications at startup.

You do a file.sh (with the commands) and add it.

I hope help you.

Revision history for this message
ernie (ernieanglade-yahoo) said :
#2

Thanks for the quick response.

Forgive my ignorance, I have a couple of clarification questions though.

1) Since "sudo -s" prompts for a password, how do I bypass this? In other words, how do I pass the password to "sudo" within that ".sh" file?

2) Does the file.sh need to be in any particular folder? Also, does it need to be an executable file?

Thanks for your patience.

Revision history for this message
Monkey (monkey-libre) said :
#3

Into System > preferences > applications at startup.

Name: something

order: sh echo "base=0xb0000000 size=0x10000000 type=write-combining" >| /proc/mtrr
or
order: sh /full_patch/file.sh

commentary: something

I don know if you need use sudo but I think not.

Revision history for this message
ernie (ernieanglade-yahoo) said :
#4

It didn't work without "sudo".

Also I tried running the echo command without sudo in a terminal session. Got some batch error message about insufficient permission.

Revision history for this message
Simon Déziel (sdeziel) said :
#5

You can allow a command to be run with root privileges without prompting for password. You only need to add a line like this to the sudoers file using "sudo visudo" :

ernie ALL=NOPASSWD: /full/path/to/file.sh

Revision history for this message
ernie (ernieanglade-yahoo) said :
#6

As directed above, I appended the line to the sudoers file. However, it didn't work. That is the line "reg03: base=0x0b0000000 ( 2816MB), size= 256MB, count=1: write-combining" did not get added to the /proc/mtrr file after running the "echo "base=0xb0000000 size=0x10000000 type=write-combining" >| /proc/mtrr" command.

The following did not work either when I try to execute the file in terminal.

ernie@ernie-laptop:~$ sh /home/ernie/Documents/myscript.sh
/home/ernie/Documents/myscript.sh: 2: cannot create /proc/mtrr: Permission denied
ernie@ernie-laptop:~$

The content of myscript.sh is:
#!/bin/sh
echo "base=0xb0000000 size=0x10000000 type=write-combining" >| /proc/mtrr

Revision history for this message
Sam_ (and-sam) said :
#7
Revision history for this message
ernie (ernieanglade-yahoo) said :
#8

Folks, I found the solution from another thread. That is to add the "echo ..." command to the /etc/rc.local file - before the "exit 0" line.