LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Server
User Name
Password
Linux - Server This forum is for the discussion of Linux Software used in a server related context.

Notices


Reply
  Search this Thread
Old 09-30-2008, 01:08 AM   #1
cdestiny
LQ Newbie
 
Registered: Jun 2007
Distribution: CentOS,Redhat
Posts: 25

Rep: Reputation: 15
Grant normal user to run certain script with root access


Hi,

Recently i have complain from user that the vnc session failed to create as the lock in /tmp/. The lock created eg: .X0-lock , .X1-lock . Only root can remove the lock.

So i have written a simple script for the user to trigger and remove the lock files.

Code:
#!/bin/sh

cd /tmp
ls -al | grep "\-lock" | awk '{print $9}' > /tmp/flist.txt
for i in `cat /tmp/flist.txt`
do
        cd /tmp
        rm -rf $i
done


echo "Finish flushing"
It running with root account.

So i visudo and add in the row
Code:
john ALL=NOPASSWD: /usr2/flush.sh
Then i su as john and run the flush script. These are the error message produced:

rm: cannot remove `.X0-lock': Operation not permitted
rm: cannot remove `.X1-lock': Operation not permitted


Please advice and let me know if i did something wrong. Thanks in advance.

Last edited by cdestiny; 09-30-2008 at 02:48 AM.
 
Old 09-30-2008, 01:23 AM   #2
Mr. C.
Senior Member
 
Registered: Jun 2008
Posts: 2,529

Rep: Reputation: 63
Your script is dangerous, and will happily remove any files containing the letters "lock", such as "block", "clock", "someother.lock", and even ".X0-lock" as you've discovered. If you want to remove files named .lock*, simplify your entire script to the single command:

rm -f /tmp/.lock*
 
Old 09-30-2008, 01:51 AM   #3
cdestiny
LQ Newbie
 
Registered: Jun 2007
Distribution: CentOS,Redhat
Posts: 25

Original Poster
Rep: Reputation: 15
Quote:
Originally Posted by Mr. C. View Post
Your script is dangerous, and will happily remove any files containing the letters "lock", such as "block", "clock", "someother.lock", and even ".X0-lock" as you've discovered. If you want to remove files named .lock*, simplify your entire script to the single command:

rm -f /tmp/.lock*
Thanks for the reply.

I have edited my script on above.
The lock generated is usually X1-lock , not a .lock.
 
Old 09-30-2008, 01:54 AM   #4
Mr. C.
Senior Member
 
Registered: Jun 2008
Posts: 2,529

Rep: Reputation: 63
I see. Your first post indicated "/tmp/.lock", so there's the disconnect.

Everything OK now?
 
Old 09-30-2008, 02:42 AM   #5
cdestiny
LQ Newbie
 
Registered: Jun 2007
Distribution: CentOS,Redhat
Posts: 25

Original Poster
Rep: Reputation: 15
Quote:
Originally Posted by Mr. C. View Post
I see. Your first post indicated "/tmp/.lock", so there's the disconnect.

Everything OK now?
Ah... i missed 1 important step. include sudo infront of the command......
It is now working. Thanks for your help.

Last edited by cdestiny; 09-30-2008 at 02:55 AM.
 
  


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



Similar Threads
Thread Thread Starter Forum Replies Last Post
How to give root access to normal user for one day. unix_anand Linux - Security 3 10-14-2008 05:45 AM
providing the root access to normal user raghuvamsi Linux - General 3 06-11-2008 12:38 AM
how to run root command having normal user permission ravi.patil Linux - Newbie 7 05-21-2006 02:21 PM
Can you connect to internet as normal user without run pppd as root ? nasty_daemon Linux - Networking 2 09-13-2005 01:43 AM
Give Root Access To A Normal User waknauss Linux - Security 2 11-11-2004 09:00 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Server

All times are GMT -5. The time now is 09:35 AM.

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