LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   This script needs to be executed as root to operate properly (https://www.linuxquestions.org/questions/linux-newbie-8/this-script-needs-to-be-executed-as-root-to-operate-properly-546456/)

thepierre 04-16-2007 08:28 AM

This script needs to be executed as root to operate properly
 
I am trying to install this: linux-acu-driver-v21.tar.gz

I downloaded from Cisco.com

When I run the command sh install or ./install I get:

This script needs to be executed as root to operate properly

I switch to root:

sudo su
enter my password
and run the command again, and still get the error.

I also logged out and logged back in as root and still get the error.
What am I missing here?

Thanks.

coolb 04-16-2007 08:39 AM

what if you do 'sh ./install.sh' ?

thepierre 04-16-2007 09:01 AM

It tells me this:

Can't open ./install.sh

MensaWater 04-16-2007 09:13 AM

Since it is a "script" you should be able to view its contents (vi the file or cat it). Go to the line that has the message you're seeing and look at the surrounding code to see how it is determining which user is running it.

I could understand if it failed on the su to root because some things use "real" id as opposed to "effective" id. When you su your real ID is the one you su'd from and your effective id is the on su'd to.

However I can't imagine why it would complain if you did a direct login as root because both your real and effective ids would be root.

thepierre 04-16-2007 09:23 AM

Here is what the install script says:

if [ "$UID" != "0" ]
then
echo "This script needs to be executed as root to operate properly."
exit 1
fi

if [ $# -ne 0 ]
then
while getopts ":i:du:r:du:RC" Option

~~~~~~~~~~~~~~

Can I make a change to the script to make it work?

MensaWater 04-16-2007 09:40 AM

= is for string comparisons.

It might work to change it to -ne for numeric:

Code:

if [ $UID -ne 0 ]
then
echo "This script needs to be executed as root to operate properly."
exit 1
fi

Before you start the script do "echo $UID" to verify it is in fact 0.
Make sure the script doesn't have any line that tries to set the UID value and thereby overrides your real UID. Examples:
UID=`some command`
UID=value

thepierre 04-16-2007 09:55 AM

Ok, when I changed the code, I got a mountain of error messages, and that didn't work.

I checked my UID and it returned 1000

The script does not mention UID anywhere else except that one line.

MensaWater 04-16-2007 09:59 AM

Your $UID after direct login as root is 1000? If so that is your problem.

Type "grep ^root /etc/passwd"

Verify the 3rd colon separate field is 0 rather than 1000.

If not post what distro you're using. There are some that are sudo only I think and maybe you have one of those. If so I won't be able to help because (Thank God) I don't have one - but someone else may be able to do so.

thepierre 04-16-2007 10:06 AM

I changed to root, and the UID is 0.

It still gives me the error.

I am using Ubuntu 7.04

MensaWater 04-16-2007 10:47 AM

When you say the UID is 0 do you mean "echo $UID" returned "0"? If so the original script should work. I just did a test using that syntax and it worked fine even when I did an su.

What is the very first line of the script? If it is something like:
#!/bin/bash
That is an interpreter specification line. Make sure whatever is specified after #! exists and is not SUID:
Example: ls -l /bin/bash
returns: -rwxr-xr-x 1 root root 686520 May 10 2005 /bin/bash
If you saw "rwsr-x-r-x and the file was NOT owned by root then it would be changing the shell to run as whoever the owner was even though you had logged in as root. This shouldn't be the case but is something to check.

thepierre 04-16-2007 11:20 AM

Ok, I ran that command, and got this:

-rwxr-xr-x 1 root root 700560 2007-04-10 19:32 /bin/bash


I went back to cisco.com as root and re downloaded the file, and it still doesn't work, I really don't get what the problem is.

MensaWater 04-16-2007 11:59 AM

I wasn't saying to run "ls -l /bin/bash" - I was using that as an example if "#!/bin/bash" was the first line of the script. Is it?

thepierre 04-16-2007 12:08 PM

Yes it is.

Here is what I see, the first few lines of the script:

#!/bin/sh
###############################################################
# kpciinstall 2.0.1 raw 4/17/02 #
# kpciinstall 2.0.2 raw 4/17/02 Changes for RH 6.2 #
# kpciinstall 2.0.3 raw 4/17/02 Changes for user auth in wep #
# setkey functions.
# kpciinstall 2.0.4 taw 4/18/02 Fix compiler breakage #
# Script to build/install the 2.0 version PCMCIA MIC and #
# the miniPCI drivers and utilities. With -R argument #
# utilities and drivers are removed #
# install 2.0.5 4/05/03 change the world #
###############################################################

KERNEL_RELEASE=`uname -r`
SRCDIR=/usr/src/linux-`uname -r`
MODBASE="/lib/modules/`uname -r`"
SRCDIRS=`echo /usr/src/*`
ARCHDIR=`pwd`

MensaWater 04-16-2007 12:15 PM

So the interpreter it is expecting is /bin/sh rather than /bin/bash.
Do your ls -l on /bin/sh. On most Linux distros it is a link to /bin/bash. So on FC4 for example I see:


ls -l /bin/sh
lrwxrwxrwx 1 root root 4 Jun 20 2006 /bin/sh -> bash

You'd want to check that then check whatever it pointed to. bash is the "Bourne Again SHell". The original Bourne Shell was simply "sh". There was a later Posix shell named "sh". There was also an enhanced shell called ksh (Korn Shell). Both bash and ksh as well as the posix shell have many features that weren't in the Bourne Shell so it could make a difference in how it runs the script.

thepierre 04-16-2007 12:26 PM

What does dash mean??

lrwxrwxrwx 1 root root 4 2007-04-02 18:24 /bin/sh -> dash


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