LinuxQuestions.org
Register a domain and help support LQ
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 09-01-2015, 06:06 PM   #1
jzoudavy
Member
 
Registered: Apr 2012
Distribution: Ubuntu, SUSE, Redhat
Posts: 180

Rep: Reputation: Disabled
why does my $PATH keeps changing


Hi all

I got redhat 6.5, and every once in a while my $PATH variable for root user changes. I am getting really really pissed off about this. It is always the same: /usr/sbin disappears and I have to add it back.

I think it is one of the tcl shell environments that the other users on this machine like to use so much causing it but I can't be sure.

anyway I can check?
 
Old 09-01-2015, 06:10 PM   #2
suicidaleggroll
LQ Guru
 
Registered: Nov 2010
Location: Colorado
Distribution: OpenSUSE, CentOS
Posts: 5,258

Rep: Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947
What do you mean you have to "add it back"? Where does it disappear from?
 
Old 09-01-2015, 06:16 PM   #3
jzoudavy
Member
 
Registered: Apr 2012
Distribution: Ubuntu, SUSE, Redhat
Posts: 180

Original Poster
Rep: Reputation: Disabled
my root user's $PATH.

Code:
# echo $PATH
/usr/lib64/qt-3.3/bin:/usr/local/bin:/bin:/usr/bin:/usr/sbin

the /usr/sbin is what keeps disappearing.
 
Old 09-01-2015, 06:22 PM   #4
suicidaleggroll
LQ Guru
 
Registered: Nov 2010
Location: Colorado
Distribution: OpenSUSE, CentOS
Posts: 5,258

Rep: Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947
I understand that, I mean the PATH gets set by root's login scripts, .bashrc, .profile, etc. just like regular users, so which login script is /usr/sbin disappearing from and where are you adding it back?

On my CentOS system, /usr/sbin gets added to root's PATH in /etc/profile:
Code:
if [ "$EUID" = "0" ]; then
    pathmunge /sbin
    pathmunge /usr/sbin
    pathmunge /usr/local/sbin
else ...
Is it possible you're sometimes accidentally running "su" instead of "su -"? The latter will update root's environment variables, the former won't.

Last edited by suicidaleggroll; 09-01-2015 at 06:23 PM.
 
Old 09-01-2015, 06:29 PM   #5
astrogeek
Moderator
 
Registered: Oct 2008
Distribution: Slackware [64]-X.{0|1|2|37|-current} ::12<=X<=14, FreeBSD_10{.0|.1|.2}
Posts: 3,876
Blog Entries: 1

Rep: Reputation: 1997Reputation: 1997Reputation: 1997Reputation: 1997Reputation: 1997Reputation: 1997Reputation: 1997Reputation: 1997Reputation: 1997Reputation: 1997Reputation: 1997
As suicidaleggroll points out, the environment depends on how you get root...

1. Login as root - you get root's full environment
2. su - to root from user login, you get root's full environment
3. su to root from user login, you retain user's environment
 
1 members found this post helpful.
Old 09-02-2015, 11:01 AM   #6
jzoudavy
Member
 
Registered: Apr 2012
Distribution: Ubuntu, SUSE, Redhat
Posts: 180

Original Poster
Rep: Reputation: Disabled
Hey all,

So right now I can't reproduce this but next time it happens I will take another look.


So here is my user's path:
as you can see it has all the directories that I need in it.

Code:
$ echo $PATH
/usr/lib64/qt-3.3/bin:/usr/local/bin:/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/sbin:/home/user/bin
Then I su into root

Code:
$ su root
 
$ echo $PATH
/usr/lib64/qt-3.3/bin:/usr/local/bin:/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/sbin:/home/user/bin
and I still retain my user's $PATH, which is fine.

and if I do this:

Code:
# su root -
# echo $PATH
/usr/lib64/qt-3.3/bin:/usr/local/bin:/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/sbin:/home/user/bin
I am now using root's $PATH. Which is also fine.

but at some point even when I do
Code:
su root -
I still find /usr/sbin is no longer in the root's $PATH.
 
Old 09-02-2015, 11:09 AM   #7
suicidaleggroll
LQ Guru
 
Registered: Nov 2010
Location: Colorado
Distribution: OpenSUSE, CentOS
Posts: 5,258

Rep: Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947
Code:
su root -
is NOT the same as
Code:
su -
As you can see from your output, the PATH did not change, you were still using your regular user's PATH.

What you're looking for is
Code:
su - root
Although the "root" is redundant since that's the default when no user is given.
 
1 members found this post helpful.
Old 09-02-2015, 11:34 AM   #8
jzoudavy
Member
 
Registered: Apr 2012
Distribution: Ubuntu, SUSE, Redhat
Posts: 180

Original Poster
Rep: Reputation: Disabled
AAAAAHHH

ok, now it makes sense. thank you. It works as advertised now.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Changing the location a module is loaded from without changing the default path zOSGuy Linux - Newbie 2 09-28-2010 03:43 PM
Changing path trotsky Linux - Newbie 3 09-03-2005 05:09 PM
changing the path liljhand Linux - Software 5 01-30-2005 05:37 AM
$PATH keeps changing? linux_dejan Linux - Software 1 04-11-2004 04:32 PM
changing PATH toxic53 Linux - Newbie 1 09-27-2001 01:04 AM


All times are GMT -5. The time now is 10:04 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration