Results 1 to 8 of 8
I have a simple command that I would like to run for a particular user upon all logins. I figured that I could add the command to the user's .bashrc; ...
- 12-30-2007 #1Linux Engineer
- Join Date
- Oct 2004
- Location
- Vancouver
- Posts
- 1,366
How do I automatically have a command run upon login?
I have a simple command that I would like to run for a particular user upon all logins. I figured that I could add the command to the user's .bashrc; is that correct or should I do it another way? Also, how would I add the command to the user's bashrc and have it automatically execute upon login's?
The command is:
Code:sudo loadkeys /usr/share/keymaps/Caps2Ctrl.map
Operating System: GNU Emacs
- 12-31-2007 #2
The short answer is that you want to put the command in ~/.bash_profile or ~/.profile. Those are executed for login shells. See the manpages for bash(1) under the FILES section for more info.
------------------------------------
Here's the long answer.
I haven't had to load keyboard translation tables, so perhaps I'm mistaken about this, but...
The loadkeys(1) manpages say:
That sounds like you only need to execute the command one time and it will apply to everyone. Have you tested this?Note that anyone having read access to /dev/console can run loadkeys
and thus change the keyboard layout, possibly making it unusable. Note
that the keyboard translation table is common for all the virtual con-
soles, so any changes to the keyboard bindings affect all the virtual
consoles simultaneously.
Note that because the changes affect all the virtual consoles, they
also outlive your session. This means that even at the login prompt the
key bindings may not be what the user expects.
- 12-31-2007 #3Linux Engineer
- Join Date
- Oct 2004
- Location
- Vancouver
- Posts
- 1,366
It's true, you only have to execute the command one time and it does apply for everyone, which is how I do it on my server. However, my eeepc restarts constantly, and I don't want to type the changes in everytime I boot-up.
I'm going to try just inserting the command into my bashrc and see if that does it.Operating System: GNU Emacs
- 12-31-2007 #4Linux Engineer
- Join Date
- Oct 2004
- Location
- Vancouver
- Posts
- 1,366
just inserting in bashrc worked like a charm
Operating System: GNU Emacs
- 12-31-2007 #5
Please at least pretend to listen to advice given.

From the bash manpages:
Every time your user opens a new shell (e.g. xterm, another bash instance) the commands within ~/.bashrc will be run. Unnecessary overkill. That's why I made the suggestions I did.~/.bashrc
The individual per-interactive-shell startup file
- 12-31-2007 #6Linux Engineer
- Join Date
- Oct 2004
- Location
- Vancouver
- Posts
- 1,366
hehe, I listened to the advice, and you were right. It's really annoying to run the script everytime open a shell.
Still trying to figure out how to have the script load on boot?Operating System: GNU Emacs
- 01-01-2008 #7Linux Engineer
- Join Date
- Feb 2005
- Posts
- 1,044
Put the command in .bash_profile as anomie suggested - that gets run just at login. If you have time, read the bash man page - it's all in there!
- 01-03-2008 #8Linux Engineer
- Join Date
- Oct 2004
- Location
- Vancouver
- Posts
- 1,366
ooh, yes, that's it. For some reason I assumed that .bashrc and .bash_profile were the same thing.

Works like a charm though
Operating System: GNU Emacs


Reply With Quote