LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - General (https://www.linuxquestions.org/questions/linux-general-1/)
-   -   Run a script as any user (https://www.linuxquestions.org/questions/linux-general-1/run-a-script-as-any-user-834503/)

Hi_This_is_Dev 09-25-2010 09:15 PM

Run a script as any user
 
I have a script that displays the IP Address of a given network interface / device name.

I have placed it in /bin/ip.sh

Code:

[root@mahadeva ~]# ip.sh eth0
192.168.56.15

But as I run it as another user, it doesn't work because the script contains the "ifconfig" command:

Code:

[root@mahadeva ~]# su - DEV
[DEV@mahadeva ~]$ ip.sh eth0
/bin/ip.sh: line 3: ifconfig: command not found


Any user can run ls command, for example, without any root privileges. I just found that my script and ls have identical ACL:


Code:

[DEV@mahadeva ~]$ getfacl /bin/ls
getfacl: Removing leading '/' from absolute path names
# file: bin/ls
# owner: root
# group: root
user::rwx
group::r-x
other::r-x

[DEV@mahadeva ~]$ getfacl /bin/ip.sh
getfacl: Removing leading '/' from absolute path names
# file: bin/ip.sh
# owner: root
# group: root
user::rwx
group::r-x
other::r-x

[DEV@mahadeva ~]$

So, how can I make my script to be executable by any user?

I looked at the visudoers file but got confused as to what entries I should make there (if that is a possible solution).

macemoneta 09-25-2010 09:23 PM

You don't need privileges, you need to specify the path - /sbin/ifconfig - since 'command not found' means that it's not in your user's path.

AlucardZero 09-25-2010 09:25 PM

Your problem is "command not found", ie ifconfig is not on the user's PATH. Use the full path (/sbin/ifconfig) in your script.

That will help. But if your script wants to do things that normally only root can do, that won't be enough.

Hi_This_is_Dev 09-25-2010 10:53 PM

Quote:

Originally Posted by AlucardZero (Post 4109068)
But if your script wants to do things that normally only root can do, that won't be enough.

What is the solution for that? :D

AlucardZero 09-26-2010 08:51 AM

chmod the script suid root. But are you really sure you want to do that?

Hi_This_is_Dev 09-26-2010 08:57 AM

Quote:

Originally Posted by AlucardZero (Post 4109428)
chmod the script suid root. But are you really sure you want to do that?

Yes, I want to experiment anything I can think of.


All times are GMT -5. The time now is 07:39 PM.