Results 1 to 5 of 5

Thread: How to load Environment Variables set for another user when "su - <user> -c"

  1. #1
    Join Date
    Dec 2008
    Location
    Philadelphia, PA, USA
    Posts
    108

    Default How to load Environment Variables set for another user when "su - <user> -c"

    Hi Guys,

    I'm having an issue here, I have installed Documentum on the openSuse and EMC doesn't provide any startup (start/stop/restart) script for /etc/init.d and I wrote my own. I have bunch of env variables that are required to start/stop Documentum and they are all set in the ~/.profile of "dmadmin" (its the user that start/stop Documentum) now when I use the following script, I get error that Env Variable not found.

    Code:
    #!/sbin/sh
    
    
    case "$1" in
    'start')
    su - dmadmin -c "/opt/documentum/dba/dmservices $1"
    ;;
    
    
    'stop')
    su - dmadmin -c "/opt/documentum/dba/dmservices $1"
    ;;
    esac
    Can somebody tell me how to load Env variables from "su" that are set for some other user?

    Regards,
    Anant
    Anant Gowerdhan
    CoFounder imSMART SolutionWare
    www.imsmart-sw.com

  2. #2

    Default Re: How to load Environment Variables set for another user when "su- <user> -c"

    -----BEGIN PGP SIGNED MESSAGE-----
    Hash: SHA1

    First, I do not know how to do this, if 'su' or 'sudo' even can do this.

    A couple of thoughts.... first, is there really a shell (or symlink to a
    shell) in /sbin as your #! line would indicate? My box does not have
    one so maybe that's interfering with things.

    Second, why not duplicate the variables into the init script? Another
    option, separate out the variable initializations to their own file
    (~dmadmin/dm-env-vars.sh) and then source that, both in your
    ~dmadmin/.profile script as well as in your
    /opt/documentum/dba/dbmservices script:

    source ~dmadmin/dm-env-vars.sh

    Doing this you would have a single source of the environment variables
    and you could have any user needing them pull them in. It may be better
    to place something like this in the /opt/documentum directory structure
    for wider access too.

    Good luck.
    -----BEGIN PGP SIGNATURE-----
    Version: GnuPG v2.0.18 (GNU/Linux)
    Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

    iQIcBAEBAgAGBQJPxiRvAAoJEF+XTK08PnB5akIQAK97C4AsKvYT+K4xZmcO+OJs
    dqjreA9zKd1kmyYBVrPvBhoVDOVdStqhekScw0jDohj5KrsblCqwsdetTc96b0Rk
    DHWmPSNpycZT66svSl9ClKNJtRnV2bgtf+vFKORbnFLKohGK7w18EyhRl7UC7Tgx
    M8IqbjjDOwBDe7H+n5WfL5JonD1XF7FQm7x/eOm8pk1arqBfwbfombe5fCp2JFuy
    6b22EcA0ed0BAASGrJ0pc4VLyftHCnAWp4l/gOwy+6S0yztuE7mzPPoRCDtv6DRa
    YLxwLFnWxjHmZXw+uNvVDFjsF9lG8L9ck1wqXg+HmC4fgbt3BHh3r7iiVAXc81Td
    mZ94ApcLp5Jm/lj6fHju3C9DaUPzqpapxFjy0gVK8YsfOmjlkIicuaB8uI2a9e7F
    d2UWmHr1lTVBjrWhpT32iPdEjPupInERlkC1i41b2svPl8ECaKejZoxzlVO6dM9X
    GY9TyolhNPF32bObQgK7A79g7HfLh0KluwqQrcrT802nZGx7Ii8ALenXNQQb+tRQ
    JMh/dPWZ+w3DEF8b1svbbfWYww40xhEz4x/HMiQGaOH/mdDZUWG6G7UfXSrxRFSc
    kr9Pv0oIegfVxZg004JIvM4Dpt5pyJUKYVX01mh6WoXqns6Yrbkk9e0Gez28sJIr
    ayYCo9UmKibk74mBHnL5
    =ErzS
    -----END PGP SIGNATURE-----

  3. #3
    Join Date
    Feb 2009
    Location
    Spain
    Posts
    25,547

    Default Re: How to load Environment Variables set for another user when "su- <user> -c"

    On 2012-05-30 15:16, anantg wrote:

    > Can somebody tell me how to load Env variables from "su" that are set
    > for some other user?


    When you do "su - dmadmin" you get the environment variables of user
    "dmadmin", and this is correct and as it should be. Some variables from the
    calling user are cleared out, as specified in the su manual, with the
    exceptions listed in the sudoers file.

    --
    Cheers / Saludos,

    Carlos E. R.
    (from 11.4 x86_64 "Celadon" at Telcontar)

  4. #4

    Default Re: How to load Environment Variables set for another user when "su - <user> -c"

    Quote Originally Posted by anantg View Post
    Can somebody tell me how to load Env variables from "su" that are set for some other user?
    I don't understand. You are in that user's environment with su.
    Compare these commands:

    Code:
    su -c 'echo $HOME'
    su someuser -c 'echo $HOME'
    sudo echo $HOME
    sudo -u someuser echo $HOME
    However you can preserve the environment in su with option -m

    Code:
    su -m -c 'echo $HOME'

  5. #5
    Join Date
    Dec 2008
    Location
    Philadelphia, PA, USA
    Posts
    108

    Thumbs up [SOLVED] Re: How to load Environment Variables set for another user when "su- <user> -c"

    Quote Originally Posted by ab View Post
    Another
    option, separate out the variable initializations to their own file
    (~dmadmin/dm-env-vars.sh) and then source that, both in your
    ~dmadmin/.profile script as well as in your
    /opt/documentum/dba/dbmservices script:

    source ~dmadmin/dm-env-vars.sh

    Doing this you would have a single source of the environment variables
    and you could have any user needing them pull them in. It may be better
    to place something like this in the /opt/documentum directory structure
    for wider access too.
    Thanks this makes sense and its working
    Anant Gowerdhan
    CoFounder imSMART SolutionWare
    www.imsmart-sw.com

Posting Permissions

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