LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Ifconfig Broken (https://www.linuxquestions.org/questions/linux-newbie-8/ifconfig-broken-800822/)

ddennis 04-08-2010 12:12 PM

Ifconfig Broken
 
I am running centos 4.5
Kernel. 2.6.18

my ifconfig is broken. and i dont know how to fix it.
I go into /sbin and i see the file but when i try and execute the command is says bash: ifconfig: command not found.
The permissions on the file are as follows
-rwxr-xr-x 1 root root 71528 May 25 2008 ifconfig
i am still new to Linux and i don't know how to fix this. any suggestions on how to fix it would be great.
Thanks.

troop 04-08-2010 12:22 PM

# sudo vi /etc/profile.d/env.sh
add strings
Code:

PATH=/sbin:/usr/sbin/:$PATH
export PATH USER LOGNAME MAIL HOSTNAME HISTSIZE INPUTRC

to end of file.
# . /etc/profile
# echo $PATH

Quakeboy02 04-08-2010 12:28 PM

Exactly how are you trying to execute "ifconfig"? It's probably a path problem, as "/sbin" isn't really supposed to be in your normal userid's path. Try typing this "sudo /sbin/ifconfig". If you don't have "sudo", then you need to become root and execute "/sbin/ifconfig".

camorri 04-08-2010 12:29 PM

It is probably not broken. 'Command Not Found' implies the command is not in your path. It is often not in a regular users path, but will be in the roots path.

To see what your path it set to, in a terminal type 'echo $PATH' without the quotes, just what is between them. As a regular user I get this -

Quote:

$ echo $PATH
/usr/bin:/bin:/usr/local/bin:/usr/X11R6/bin/:/usr/games:/usr/lib/qt4/bin:/home/cliff/bin:/sbin
Each entry is where the system will look when I type a command. If it is found, it does it. If not, then it will return 'command not found'.

Here is the path for root on my system -
Quote:

# echo $PATH
/sbin:/usr/sbin:/bin:/usr/bin:/usr/X11R6/bin:/usr/local/bin:/usr/local/sbin:/usr/lib/qt4/bin
If you compare the two, they are different. Now, where is ifconfig? To answer that I run the command 'locate ifconfig' and the system returns
Quote:

locate ifconfig
/sbin/ifconfig
.

So you can see ifconfig will be found by root, but not by ther regular user. However, if I want to run it as a regular user, all I need to do is add the path to the command. Like this...

Quote:

$ /sbin/ifconfig
eth0 Link encap:Ethernet HWaddr 00:1D:7D:20:F4:67
inet addr:192.168.1.26 Bcast:192.168.1.255 Mask:255.255.255.0
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:171340 errors:0 dropped:0 overruns:0 frame:0
TX packets:143638 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:110034071 (104.9 MiB) TX bytes:13167384 (12.5 MiB)
Interrupt:24 Base address:0xc000

lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
UP LOOPBACK RUNNING MTU:16436 Metric:1
RX packets:14351 errors:0 dropped:0 overruns:0 frame:0
TX packets:14351 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:794028 (775.4 KiB) TX bytes:794028 (775.4 KiB)
and the command runs.

Hope this helps...

ddennis 04-08-2010 02:25 PM

Thank you all for your quick replys

This is my users $PATH
echo $PATH
/usr/kerberos/sbin:/usr/kerberos/bin:/usr/local/bin:/bin:/usr/bin:/home/ddennis/bin


this is my Root $path
/usr/kerberos/sbin:/usr/kerberos/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin


if i do a /sbin/ifconfig it does work.
so I can tell this is entirely a path issue.
As per the first reply i tried to edit the file they listed to add /sbin to the path but the file at the location /etc/profile.d/env.sh does not exist. what file do i need to edit to add the /sbin to my user accounts?

Quakeboy02 04-08-2010 02:34 PM

You should really not add /sbin to your user accounts.

nuwen52 04-08-2010 03:53 PM

Quote:

You should really not add /sbin to your user accounts.
Generally, I agree, and it doesn't take much to just simply type /sbin/ifconfig if you need it. But, if you really want to add it to the path (and assuming you use bash, which it the standard for CentOS I think), you just add:
Code:

PATH="$PATH:/sbin"
to your ~/.bashrc file. If you don't have one, just create it. Mine looks like:
Code:

# .bashrc

# Source global definitions
if [ -f /etc/bashrc ]; then
        . /etc/bashrc
fi

# User specific aliases and functions
alias ]='gnome-open'


ddennis 04-08-2010 04:21 PM

the reason i am wanting to add it to a specific to user is because I am getting e-mail notification from a cron job that is saying the ifconfig command is not found. the cron job is coming specifically from a file called collectinfo.pl. so i am trying to figure out how to get this to stop because the cron job runs every 5 min. and every time it failes i am getting a e-mail saying that the cron job had errors.

Quakeboy02 04-08-2010 04:30 PM

Simple, fix the cron job and have it execute "/sbin/ifconfig" rather than just "ifconfig". Generally, any script executing a program should use the whole path, not just the program's name. That should be one of the first thing a script-writer learns.

ddennis 04-09-2010 11:46 AM

removed. because of double post

ddennis 04-09-2010 11:50 AM

the cron job is not actually running the ifconfig command it is running a command for a file called collectinfo.pl. I believe that the collectinfo.pl in its processing is running the ifonfig command. and if there is a way to edit that .pl file I would prefer that. but i dont know if that possible.

Quakeboy02 04-09-2010 11:52 AM

"collectinfo.pl" is a perl file. It can be edited just like any other text file. Give it a shot. Make a backup first, of course.


All times are GMT -5. The time now is 03:23 PM.