Operating System - Linux
1752587 Members
4455 Online
108788 Solutions
New Discussion юеВ

bash: service: command not found

 
stripling20
Occasional Contributor

bash: service: command not found

Hi All,
When i was trying to restart or use any service, i got the error msg "bash: service: command not found" so i have to run the service from "/etc/init.d/ " and also the command "ifconfig" not working. Im still getting same error message.

so can any one tell the real problem behind that.
What we think today is our tomorrow's future
5 REPLIES 5
J. Maestre
Honored Contributor

Re: bash: service: command not found

The path to those files is not in your PATH variable, so bash doesn't find them (verify with "echo $PATH").

To solve it, edit ~/.profile and add those paths to the PATH variable (it should be defined there).
Matti_Kurkela
Honored Contributor

Re: bash: service: command not found

The root cause is a minor flaw in default login scripts: if you use "su" or "sudo -s" to become root, you will have root privileges but the PATH variable will include only the command directories intended for regular users. Some Linux distributions have already fixed this, others have not.

The administrative commands like "service" and "ifconfig" are located in /sbin or /usr/sbin, which are normally not added to regular users' PATH.

If you use "su -" or "sudo -i" (if your sudo version is recent enough) to become root, the environment of the root session is completely reinitialized and will include the sbin directories.

If you need to fix it, find out which login scripts are executed when using your favorite method of becoming root, then add this to the appropriate script:

export PATH="/sbin:/usr/sbin:/usr/local/sbin:$PATH"

MK
MK
Jupinder Bedi
Respected Contributor

Re: bash: service: command not found

you can check it as follows


# which ifconfig

it will give you the path where this command reside

try to run it from that path

#/usr/bin/ifconfig eth0

like that

and also you can set this path in your .profile like mentioned above.


Good luck
All things excellent are as difficult as they are rare
Steven E. Protter
Exalted Contributor

Re: bash: service: command not found

Shalom,

/sbin/service

That is where it is supposed to be. If its not at that location this could be the cause.

If it is in /sbin then look at the PATH variable.

SEP
Steven E Protter
Owner of ISN Corporation
http://isnamerica.com
http://hpuxconsulting.com
Sponsor: http://hpux.ws
Twitter: http://twitter.com/hpuxlinux
Founder http://newdatacloud.com
Steven Schweda
Honored Contributor

Re: bash: service: command not found

> # which ifconfig
> it will give you the path where this
> command reside
> try to run it from that path

Sure, _if_ it's already _on_ your PATH.
Otherwise, you'll be wasting your time.

man which

> Good luck

You'll need it, if you rely on advice like
this.


> /sbin/service
> That is where it is supposed to be.

That may depend on whose GNU/Linux kit you're
using. Around here, for example:

debi# service
-bash: service: command not found

debi# ls -l /sbin/service
ls: cannot access /sbin/service: No such file or directory

debi# man service
No manual entry for service

debi# uname -a
Linux debi 2.6.26-2-mckinley #1 SMP Thu Nov 5 03:58:10 UTC 2009 ia64 GNU/Linux

On the other hand:

debi# which ifconfig
/sbin/ifconfig

So, adding "/sbin" to your PATH would
probably be helpful. (Obviously, it's on
mine.)

General advice:

Especially in a Linux forum, output from
"uname -a" can be helpful when asking about
almost anything. Linux comes in many
different forms, and no one is born knowing
which one you're using.