Results 1 to 10 of 10

Thread: Special user, .bashrc not being executed upon login

  1. #1
    Join Date
    Jun 2009
    Location
    Alabama
    Beans
    2,232

    Question Special user, .bashrc not being executed upon login

    I have started using the PostgreSQL database server. It created a special user, postgres, when I installed the package. Except for one little thing, it is working great.

    When I "su - postgres" or "su -l postgres" (which should be equivalent), the .bashrc I created in user postgres's home directory is not being executed. If, after login, I run ". ./.bashrc", the profile is executed and does exactly what I want, which is just setting a couple of environment variables. I have verified that the user's shell is bash and that the .bashrc profile is in its home directory, owned by user postgres.

    I even tried making the file executable, but that did not help.

    I have read the man pages for both su and bash, and both seem to indicate that the profile should be being executed. What am I missing?

    Thanks,
    Tim
    Cyberpower PC, Core i5 2500 3.3 gHz, 8GB DDR3, ATI 6770 1GB, Samsung BX 2440 LED 1080p, 1 TB SATA III, 2 TB SATA III, Siduction Linux 64-bit

  2. #2
    Join Date
    May 2008
    Location
    United Kingdom
    Beans
    5,263
    Distro
    Ubuntu

    Re: Special user, .bashrc not being executed upon login

    ~/.bashrc is run on opening a new terminal, not when logging in.

    Place your code at the end of ~/.profile instead and let me know if that works.
    Always make regular backups of your data (and test them).
    Visit Full Circle Magazine for beginners and seasoned Linux enthusiasts.

  3. #3
    Join Date
    Jun 2009
    Location
    Alabama
    Beans
    2,232

    Red face Re: Special user, .bashrc not being executed upon login

    That did work, thank you. I guess I misunderstood the su manpage.

    I always used .profile when I worked on Solaris systems, professionally, but for some reason I switched to using .bashrc when I moved to Linux. I think I was hitting some situations when .profile was not working the way I wanted it to on Linux. In Solaris, it had always worked whether I was opening a new terminal or running su from an existing terminal.

    Thanks,
    Tim
    Cyberpower PC, Core i5 2500 3.3 gHz, 8GB DDR3, ATI 6770 1GB, Samsung BX 2440 LED 1080p, 1 TB SATA III, 2 TB SATA III, Siduction Linux 64-bit

  4. #4
    Join Date
    May 2008
    Location
    United Kingdom
    Beans
    5,263
    Distro
    Ubuntu

    Re: Special user, .bashrc not being executed upon login

    Quote Originally Posted by ratcheer View Post
    ... I misunderstood the su manpage.
    It's not there; it's in the bash manual.

    To summarise:

    Bash runs the following scripts on login:

    • /etc/profile
    • The first found of ~/.bash_profile, ~/.bash_login, ~/.profile (Ubuntu by default uses the latter)

    On entering an interactive terminal, Bash also executes:

    • /etc/bash.bashrc
    • ~/.bashrc

    On logout, Bash runs:

    • ~/.bash_logout
    • /etc/bash.bash.logout
    Always make regular backups of your data (and test them).
    Visit Full Circle Magazine for beginners and seasoned Linux enthusiasts.

  5. #5
    Join Date
    Jun 2009
    Location
    Alabama
    Beans
    2,232

    Thumbs up Re: Special user, .bashrc not being executed upon login

    Ok, thanks again. Here is the part that confused me:

    Code:
    The optional argument - may be used to provide an environment similar to what the user would expect had the user logged in directly.
    Also, there are similar details in the explanation of the -l option.

    Tim
    Cyberpower PC, Core i5 2500 3.3 gHz, 8GB DDR3, ATI 6770 1GB, Samsung BX 2440 LED 1080p, 1 TB SATA III, 2 TB SATA III, Siduction Linux 64-bit

  6. #6
    Join Date
    Dec 2006
    Location
    brisbane,australia
    Beans
    24

    Re: Special user, .bashrc not being executed upon login

    Quote Originally Posted by Paddy Landau View Post
    On entering an interactive terminal, Bash also executes:

    • /etc/bash.bashrc
    • ~/.bashrc
    I don't think is also executes those. I think it only executes ~/.bashrc.
    http://www.gnu.org/software/bash/man...tup-Files.html

  7. #7
    Join Date
    May 2008
    Location
    United Kingdom
    Beans
    5,263
    Distro
    Ubuntu

    Re: Special user, .bashrc not being executed upon login

    Quote Originally Posted by felipe1982 View Post
    I don't think is also executes those. I think it only executes ~/.bashrc.
    http://www.gnu.org/software/bash/man...tup-Files.html
    You may not think so, but it does.

    I tested this today on Ubuntu, both 12.04 and 12.10.

    When you enter an interactive terminal, Bash does indeed execute both /etc/bash.bashrc and ~/.bashrc.
    Always make regular backups of your data (and test them).
    Visit Full Circle Magazine for beginners and seasoned Linux enthusiasts.

  8. #8
    Join Date
    Dec 2006
    Location
    brisbane,australia
    Beans
    24

    Re: Special user, .bashrc not being executed upon login

    Quote Originally Posted by Paddy Landau View Post
    When you enter an interactive terminal, Bash does indeed execute both /etc/bash.bashrc and ~/.bashrc.
    That's because a non-login shell calls .bashrc, which then sources /etc/bashrc. But an non-login shell does not call .bash_profile or /etc/profile.

    Interacitve Login: The shell calls /etc/profile, then the first of .bash_profile, .bash_login, .profile.

    Interactive non-login: The shell only calls .bashrc

    If defined to do so, the files bash calls by default may subsequently call other files in the system.

  9. #9
    Join Date
    May 2008
    Location
    United Kingdom
    Beans
    5,263
    Distro
    Ubuntu

    Re: Special user, .bashrc not being executed upon login

    Quote Originally Posted by felipe1982 View Post
    That's because a non-login shell calls .bashrc, which then sources /etc/bashrc. But an non-login shell does not call .bash_profile or /etc/profile.

    Interacitve Login: The shell calls /etc/profile, then the first of .bash_profile, .bash_login, .profile.

    Interactive non-login: The shell only calls .bashrc

    If defined to do so, the files bash calls by default may subsequently call other files in the system.
    Thanks for the clarification.

    My .bashrc does not source /etc/bashrc, so I don't know how it gets executed. I wonder if your system and my system are different? I am using Ubuntu 12.04.
    Always make regular backups of your data (and test them).
    Visit Full Circle Magazine for beginners and seasoned Linux enthusiasts.

  10. #10
    Join Date
    Dec 2006
    Location
    brisbane,australia
    Beans
    24

    Re: Special user, .bashrc not being executed upon login

    I use opensuse, centos, and rhel. I'm not a Debian-based-distro fan , although i have used them in the past...

    You can try a few things to discover how your /etc/bashrc is being sourced by your shell, if your .bashrc isn't sourcing it.

    1. You can
      Code:
      egrep -rl '/etc/bashrc' $DIRECTORY
      Where $DIRECTORY can be `/' or `/etc' or $HOME
    2. You can remove, or rename, your startup files (.bash*) and try again.
    3. a non-login shell is (normally) one where you don't enter your password. So, after logging into your system, open a terminal, and just type "bash". That will launch a NEW interactive non-login shell.
    4. Lastly, maybe Ubuntu has a different way of doing things ???

    Cheers,
    Felipe

Tags for this Thread

Bookmarks

Posting Permissions

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