LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
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, 05:06 PM   #1
jzoudavy
Member
 
Registered: Apr 2012
Distribution: Ubuntu, SUSE, Redhat
Posts: 188

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, 05:10 PM   #2
suicidaleggroll
LQ Guru
 
Registered: Nov 2010
Location: Colorado
Distribution: OpenSUSE, CentOS
Posts: 5,573

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

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, 05:22 PM   #4
suicidaleggroll
LQ Guru
 
Registered: Nov 2010
Location: Colorado
Distribution: OpenSUSE, CentOS
Posts: 5,573

Rep: Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142
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 05:23 PM.
 
Old 09-01-2015, 05:29 PM   #5
astrogeek
Moderator
 
Registered: Oct 2008
Distribution: Slackware [64]-X.{0|1|2|37|-current} ::12<=X<=15, FreeBSD_12{.0|.1}
Posts: 6,258
Blog Entries: 24

Rep: Reputation: 4193Reputation: 4193Reputation: 4193Reputation: 4193Reputation: 4193Reputation: 4193Reputation: 4193Reputation: 4193Reputation: 4193Reputation: 4193Reputation: 4193
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, 10:01 AM   #6
jzoudavy
Member
 
Registered: Apr 2012
Distribution: Ubuntu, SUSE, Redhat
Posts: 188

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, 10:09 AM   #7
suicidaleggroll
LQ Guru
 
Registered: Nov 2010
Location: Colorado
Distribution: OpenSUSE, CentOS
Posts: 5,573

Rep: Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142
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, 10:34 AM   #8
jzoudavy
Member
 
Registered: Apr 2012
Distribution: Ubuntu, SUSE, Redhat
Posts: 188

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 02:43 PM
Changing path trotsky Linux - Newbie 3 09-03-2005 04:09 PM
changing the path liljhand Linux - Software 5 01-30-2005 04:37 AM
$PATH keeps changing? linux_dejan Linux - Software 1 04-11-2004 03:32 PM
changing PATH toxic53 Linux - Newbie 1 09-27-2001 12:04 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 11:53 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
Open Source Consulting | Domain Registration