- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- su -c and user environment
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Discussions
Discussions
Forums
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО01-01-2008 05:25 AM
тАО01-01-2008 05:25 AM
I try to run a script from the root user using the su -c command. The script to be called is using the $HOME environment. However, the $HOME env is till pointing to the root user instead of the intended su user. Below is what I get when I ru the su command from the root user:
$ su wsm-dev1 -c "echo $HOME"
/root
As you can see, the $HOME is echoed to be /root instead of /home/wsm-dev1 which is the home dir for the user wsm-dev1.
Does anyone have idea on how to get the user env instead of the root user?
Thanks.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО01-01-2008 05:53 AM
тАО01-01-2008 05:53 AM
Re: su -c and user environment
# su - wsm-dev1 -c "echo \$HOME"
Use the 'su -' to cause the profile of the target user to be sourced (read) as if this were a login.
Escape ('\') the HOME variable so that the shell doesn't interpret the variable before it is passed along.
Also, consider the effect of the 'SU_KEEP_ENV_VARS' if you have defined it in your '/etc/default/security' file:
http://www.docs.hp.com/en/B3921-60631/security.4.html
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО01-02-2008 01:39 AM
тАО01-02-2008 01:39 AM
Re: su -c and user environment
su - for the profile of the target to be sourced.
and "/" for the shell is always good for use.
try this and you may get the answer.
if the answer is correct please gimme the points.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО01-02-2008 06:21 AM
тАО01-02-2008 06:21 AM
Re: su -c and user environment
This isn't helpful. There are at least 3 things wrong with it. Better to use JRF' solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО01-02-2008 01:06 PM
тАО01-02-2008 01:06 PM
SolutionI'm missing the most obvious solution in preventing the expansion of the $-variable and using single quotes:
su - wsm-dev1 -c 'echo $HOME'
mfG Peter
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО01-03-2008 12:58 AM
тАО01-03-2008 12:58 AM
Re: su -c and user environment
Yes, that works. I guess it depends on how many $ variable are there and which need to be replaced by the current shell and which by the su shell.