Find the answer to your Linux question:
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; ...
  1. #1
    Linux 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

  2. #2
    Linux Guru anomie's Avatar
    Join Date
    Mar 2005
    Location
    Texas
    Posts
    1,692
    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:
    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.
    That sounds like you only need to execute the command one time and it will apply to everyone. Have you tested this?

  3. #3
    Linux 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

  4. #4
    Linux Engineer
    Join Date
    Oct 2004
    Location
    Vancouver
    Posts
    1,366
    just inserting in bashrc worked like a charm
    Operating System: GNU Emacs

  5. #5
    Linux Guru anomie's Avatar
    Join Date
    Mar 2005
    Location
    Texas
    Posts
    1,692
    Please at least pretend to listen to advice given.

    From the bash manpages:
    ~/.bashrc
    The individual per-interactive-shell startup file
    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.

  6. #6
    Linux 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

  7. #7
    scm
    scm is offline
    Linux 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!

  8. #8
    Linux 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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
...