Console commands on startup

Asked by kokoko

Hello there,

I know that the question "How can I execute a command at every startup" is classic nowdays, but I'd like a definite answer. First of all, let me declare that I don't mean graphical applications like gaim or gparted, but console commands like "mv ~/.ske ~/.skecc". I have heard that you can do that by adding them in ~/.xinitrc or /etc/bashrc, but is that true?
Also, how can I execute commands that require root access in the startup, like "sudo mv ~/.ske ~/.skecc". That required a rule in the sudo config file, right?

Thanks!

Question information

Language:
English Edit question
Status:
Solved
For:
Ubuntu Edit question
Assignee:
No assignee Edit question
Solved by:
Hanusz leszek
Solved:
Last query:
Last reply:
Revision history for this message
Hanusz leszek (leszek-skynet) said :
#1

Hello,

You can add commands which will be run as root each time the computer boot in /etc/rc.local

Because it is running as root, you don't need to add "sudo"

The /etc/bashrc is to run commands required each time a terminal is started.
The .xinitrc is to run commands each time X is started (the graphical server)

Revision history for this message
kokoko (bababa) said :
#2

Thanks for the reply.
Is there a file to add commands to be executed as the normal user, or I can just do that with: sudo su <user> && <command> ?

Revision history for this message
Best Hanusz leszek (leszek-skynet) said :
#3

You specify the user with sudo with the -u parameter:

sudo -u <username> <command>

Revision history for this message
kokoko (bababa) said :
#4

Thanks Hanusz leszek, that solved my question.

Revision history for this message
kokoko (bababa) said :
#5

Aw, and something else.
If, for example, I add this: "echo hay > ks.txt" in /etc/rc.local, where will ks.txt be? I know that I can define that by adding /home/habeeb/ks.txt or something, but I wonder where it will appear without defining the directory. The root home folder?

Revision history for this message
Hanusz leszek (leszek-skynet) said :
#6

I don't know, you should try your example and find where the file is.