LinuxQuestions.org
Help answer threads with 0 replies.
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 08-01-2009, 02:28 PM   #1
vbsaltydog
Member
 
Registered: Nov 2005
Distribution: CentOS
Posts: 154

Rep: Reputation: 15
shell cant find commands


I am on a CentOS 5 box and logged in as a standard user but su to root and when I try to run commands like "service named restart" or "useradd -c username -d /path/to home dir"

I get an error that command service or command useradd not found. I know they exist on the system. I remember using them before I changed the root shell to bash. I think that's when the errors began. Anyway, I changed the shell for root to /bin/sh and I still get the errors.

Any help is appreciated.
 
Old 08-01-2009, 02:33 PM   #2
jdkaye
LQ Guru
 
Registered: Dec 2008
Location: Westgate-on-Sea, Kent, UK
Distribution: Debian Testing Amd64
Posts: 5,464

Rep: Reputation: Disabled
Quote:
Originally Posted by vbsaltydog View Post
I am on a CentOS 5 box and logged in as a standard user but su to root and when I try to run commands like "service named restart" or "useradd -c username -d /path/to home dir"

I get an error that command service or command useradd not found. I know they exist on the system. I remember using them before I changed the root shell to bash. I think that's when the errors began. Anyway, I changed the shell for root to /bin/sh and I still get the errors.

Any help is appreciated.
From your shell as root type
Code:
echo $PATH
You should see /usr/sbin as part of your path or there's a problem.
cheers,
jdk
 
Old 08-01-2009, 02:40 PM   #3
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976
Did you use su - for switching to root? Without the - sign, you don't get the root's PATH, but the environment of the user is preserved.
 
Old 08-01-2009, 02:43 PM   #4
vbsaltydog
Member
 
Registered: Nov 2005
Distribution: CentOS
Posts: 154

Original Poster
Rep: Reputation: 15
output of $PATH is:

/usr/kerberos/sbin:/usr/kerberos/bin:/usr/local/bin:/bin:/usr/bin:/home/my_user_before_the_su_to_root/bin
 
Old 08-01-2009, 02:48 PM   #5
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976
Quote:
Originally Posted by vbsaltydog View Post
output of $PATH is:

/usr/kerberos/sbin:/usr/kerberos/bin:/usr/local/bin:/bin:/usr/bin:/home/my_user_before_the_su_to_root/bin
The last directory means it is the user's environment. However, /usr/kerberos/sbin should not be there. You have to check the definition of PATH through the system configuration files: /etc/profile, /etc/bashrc or similar. Anyway, I still remain of the idea that maybe you missed the - in the su command.
 
Old 08-01-2009, 02:50 PM   #6
vbsaltydog
Member
 
Registered: Nov 2005
Distribution: CentOS
Posts: 154

Original Poster
Rep: Reputation: 15
what - in the su command ?
 
Old 08-01-2009, 02:54 PM   #7
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976
See my post #3 above. You have to use
Code:
su -
to get the login environment of root, otherwise the env of the user is preserved and the PATH does not contain /sbin and /usr/sbin.
 
Old 08-01-2009, 03:01 PM   #8
vbsaltydog
Member
 
Registered: Nov 2005
Distribution: CentOS
Posts: 154

Original Poster
Rep: Reputation: 15
That worked. I have never had to do that before so I didn't think to look at the su switches. Thanks for the help.
 
Old 08-01-2009, 08:32 PM   #9
scottro11
Member
 
Registered: Jun 2009
Location: NYC
Posts: 260

Rep: Reputation: 58
I have a little page that covers it, for what it's worth.

http://home.roadrunner.com/~computer...su/rhpath.html

Removal of sbin from non-root users' default path is actually rather common. Mepis also does it. Ubuntu and its variants don't, as they want you to use sudo.
 
Old 08-02-2009, 09:56 AM   #10
ubu.fedo
LQ Newbie
 
Registered: Jul 2009
Posts: 7

Rep: Reputation: 0
# whereis command
display:/dirA/dirB/command ...

# /dirA/dirB/command That maybe worked.
 
  


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
more shell commands mf5160 Linux - Software 3 03-14-2007 02:41 PM
about shell commands nesta Linux - Newbie 3 12-12-2006 06:40 PM
Alias or shell script to confirm 'exit' commands from a shell rose_bud4201 Programming 2 03-08-2006 03:34 PM
commands in shell? kalleanka Linux - General 9 02-01-2006 08:38 AM
Cannot find reliable information on shell commands Rakin Linux - Newbie 7 02-21-2003 11:55 AM


All times are GMT -5. The time now is 11:11 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