LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 09-25-2010, 09:15 PM   #1
Hi_This_is_Dev
Member
 
Registered: May 2009
Location: India
Distribution: On my PC I use RHEL, at office AIX, Solaris, HP-UX, RHEL.
Posts: 254

Rep: Reputation: 18
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).
 
Old 09-25-2010, 09:23 PM   #2
macemoneta
Senior Member
 
Registered: Jan 2005
Location: Manalapan, NJ
Distribution: Fedora x86 and x86_64, Debian PPC and ARM, Android
Posts: 4,593
Blog Entries: 2

Rep: Reputation: 344Reputation: 344Reputation: 344Reputation: 344
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.
 
Old 09-25-2010, 09:25 PM   #3
AlucardZero
Senior Member
 
Registered: May 2006
Location: USA
Distribution: Debian
Posts: 4,824

Rep: Reputation: 615Reputation: 615Reputation: 615Reputation: 615Reputation: 615Reputation: 615
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.
 
Old 09-25-2010, 10:53 PM   #4
Hi_This_is_Dev
Member
 
Registered: May 2009
Location: India
Distribution: On my PC I use RHEL, at office AIX, Solaris, HP-UX, RHEL.
Posts: 254

Original Poster
Rep: Reputation: 18
Quote:
Originally Posted by AlucardZero View Post
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?
 
Old 09-26-2010, 08:51 AM   #5
AlucardZero
Senior Member
 
Registered: May 2006
Location: USA
Distribution: Debian
Posts: 4,824

Rep: Reputation: 615Reputation: 615Reputation: 615Reputation: 615Reputation: 615Reputation: 615
chmod the script suid root. But are you really sure you want to do that?
 
Old 09-26-2010, 08:57 AM   #6
Hi_This_is_Dev
Member
 
Registered: May 2009
Location: India
Distribution: On my PC I use RHEL, at office AIX, Solaris, HP-UX, RHEL.
Posts: 254

Original Poster
Rep: Reputation: 18
Quote:
Originally Posted by AlucardZero View Post
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.
 
  


Reply



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 On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
I need a script to run at user logout jr_linux Linux - Newbie 3 03-25-2008 02:41 PM
How to run script of another user from root? sikandar Linux - Software 4 09-05-2007 03:42 AM
how do I make sure that the user that is going to run the script is a root user??? nikold01 Linux - General 3 09-10-2004 07:54 AM
Allow user to run their own cgi script samwong Linux - Newbie 5 05-25-2004 10:22 PM
Run a script as a different user dtheorem Programming 5 11-05-2003 05:57 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 05:32 PM.

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
Open Source Consulting | Domain Registration