Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers


UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

Closed Thread    
 
Thread Tools Search this Thread Display Modes
    #1  
Old 07-04-2012
Registered User
 
Join Date: Dec 2010
Posts: 88
Thanks: 30
Thanked 0 Times in 0 Posts
Execute a command as root from normal user

Hi ,

I am trying to stop and start a process using the below code. I have sudo access on my machine

Code:
## PID = process id
echo "$PASSWD" | sudo -S kill -9 <PID>

echo "$PASSWD" | sudo -S /opt/abc/startserver
/opt/abc/startserver: error while loading shared libraries: librts.so: cannot open shared object file: No such file or directory

But its working if i follow the below procedure

Code:
$ sudo -i
# opt/abc/startserver
Server Started

How do i execute a process with sudo access in my case , i have tried -p <promt option > but no use

any help is much appreciated
Sponsored Links
    #2  
Old 07-04-2012
...@...
 
Join Date: Feb 2004
Location: NM
Posts: 9,646
Thanks: 164
Thanked 641 Times in 618 Posts
You are running the upper code in a crontab? In any case it looks like the environment in the first example is missing LD_LIBRARY_PATH variable.
Sponsored Links
    #3  
Old 07-04-2012
Registered User
 
Join Date: Dec 2010
Posts: 88
Thanks: 30
Thanked 0 Times in 0 Posts
First code is a script file not in cron.

The former are the series of commands executed in shell one after the other (not through scripting)

Code:
The below commands are working fine
<<command 1>>
$sudo -i 
<<command 2>>
# opt/abc/startserver Server Started 

i tried 
$sudo /opt/abc/startserver    , it throws the same error

    #4  
Old 07-04-2012
vbe's Avatar
vbe vbe is offline Forum Staff  
Moderator
 
Join Date: Sep 2005
Location: Switzerland - GE
Posts: 4,633
Thanks: 118
Thanked 256 Times in 245 Posts
What, as the concerned user, is the output of
Code:
 sudo -l

Sponsored Links
    #5  
Old 07-04-2012
Registered User
 
Join Date: Dec 2010
Posts: 88
Thanks: 30
Thanked 0 Times in 0 Posts
output of sudo -l
User <xyz> may run the following commands on this host:
(ALL) ALL
(ALL) ALL
Sponsored Links
    #6  
Old 07-04-2012
vbe's Avatar
vbe vbe is offline Forum Staff  
Moderator
 
Join Date: Sep 2005
Location: Switzerland - GE
Posts: 4,633
Thanks: 118
Thanked 256 Times in 245 Posts
Ok its OT but, I feel a bit concerned by your security with what I see above...
Cant you get your user to have:

Code:
n12:/home/vbe $ sudo -l
User vbe may run the following commands on this host:
    (ALL) NOPASSWD: ALL

What I mean is execution without password... since he has all rights... or you all know the passwd and could not care...

Your issue now, it look like suggests Jim, to do with the environment...To see if its that source root's .profile before executing you commands:

Code:
 .  ~root/.profile

Sponsored Links
    #7  
Old 07-05-2012
Registered User
 
Join Date: Dec 2010
Posts: 88
Thanks: 30
Thanked 0 Times in 0 Posts
Thanks vbe and jim

Finally the below code worked

Code:
## startserver is already included in the Current environment through /etc/profile
 echo "PASSWD" | sudo -S -E startserver


Code:
I dont want to try the below trick because this is just adhoc not a regular task.
 (ALL) NOPASSWD: ALL

Sponsored Links
Closed Thread

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
java version mismatch for normal user and root user frintocf Solaris 3 08-19-2011 06:02 AM
Execute Root command as Normal user abhishek1979 Shell Programming and Scripting 3 03-22-2010 01:53 PM
root user command in shell script execute as normal user mnmonu Shell Programming and Scripting 3 10-19-2009 07:42 AM
login into root from user and execute command through script pradeepreddy Shell Programming and Scripting 6 08-29-2008 02:49 AM
Other than root user .Normal user is unable to create files mallesh UNIX for Advanced & Expert Users 1 06-22-2005 12:18 PM



All times are GMT -4. The time now is 07:41 AM.