LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
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 01-07-2012, 09:01 PM   #1
gjwalsh
Member
 
Registered: Oct 2010
Location: Victoria, B.C., Canada
Distribution: OpenSuSE Tumbleweed
Posts: 30

Rep: Reputation: 0
find with root permissions to search for all files except for specified directories


On a development server, I use the find command as the root user (where the contents of /alt and /bup are not considered and filematch is the operator-supplied file name to be matched), like so:

find /* -path /alt -prune -o -path /bup - prune -o -name filematch -print

That works just fine. Otherwise we would have painfully lengthy searches reading through all the backup and archival files. They are on the one server, but they are on unique disk drives.

What I want, ideally is:

An alias for find or an alternative script (say: findcf) which would prompt the user for the file name to be searched, and which would somehow acquire root permissions to permit a full search of all directories excluding /alt and /bup. While that may prove both problematic and even vulnerable, a system-wide search without root permission would prove decidedly useless for our purposes.

I've even read commentary to the effect that the bash shell will not even permit this.

The reason behind all this is that a small group of dedicated folks helping with the ongoing development need this capability. They can be identified as members of an internal group, but that doesn't do anything for the root permission required to get the job done.

If this is an impossibility, I might build a php script to do the job where, if I recall, those permissions can be passed at execution time, while constructing a command line and passing the file name to be matched are both trivial matters.

Before I attempt that, I thought I'd ask for any help with the original bash shell execution scheme in the event I am missing something obvious. (Wouldn't be the first time :-))

My thanks for considering this and sharing what you may have already experienced.

George
 
Old 01-07-2012, 09:24 PM   #2
EricTRA
LQ Guru
 
Registered: May 2009
Location: Gibraltar, Gibraltar
Distribution: Fedora 20 with Awesome WM
Posts: 6,805
Blog Entries: 1

Rep: Reputation: 1296Reputation: 1296Reputation: 1296Reputation: 1296Reputation: 1296Reputation: 1296Reputation: 1296Reputation: 1296Reputation: 1296
Hi,

Are you familiar with sudo and how to set it up? I believe that with a correct and trimmed down confguration of sudo, for user and/or group, you can stay within 'Bash world' without the need of any external stuff.

Kind regards,

Eric
 
Old 01-07-2012, 10:18 PM   #3
T3RM1NVT0R
Senior Member
 
Registered: Dec 2010
Location: Internet
Distribution: Linux Mint, SLES, CentOS, Red Hat
Posts: 2,385

Rep: Reputation: 477Reputation: 477Reputation: 477Reputation: 477Reputation: 477
@ Reply

Hi gjwalsh,

EricTRA is right you can use sudo to meet your objective. Here is how it will go:

1. Create a group for the folks who need to run find command with root privilege.
2. Add the users to this group.
3. Run the command
Code:
visudo
at the end of the file put:

Code:
%group_name      ALL=NOPASSWD: /usr/bin/find
Where group_name will be group that you have created in step 1.

4. Save the file and exit.

Bash script part will be really simple. Here is how your bash script will look like:

Code:
#!/bin/bash
echo "Enter the name of the file that you want search"
read filename
sudo /usr/bin/find /* -path /alt -prune -o -path /bup - prune -o -name $filename -print
NOTE: Some distros like SLES require you to comment out following lines:

Code:
#Defaults targetpw   # ask for the password of the target user i.e. root
#ALL    ALL=(ALL) ALL   # WARNING! Only use this together with 'Defaults targetpw'!
for sudo to work without prompting for the password
 
Old 01-08-2012, 01:37 AM   #4
gjwalsh
Member
 
Registered: Oct 2010
Location: Victoria, B.C., Canada
Distribution: OpenSuSE Tumbleweed
Posts: 30

Original Poster
Rep: Reputation: 0
Thanks so much, EricTRA and T3RM1NVTOR, for providing such a clear and prompt leg-up for me.

Like most problems I encounter at the system level, as opposed to my applications work, the solution proposed was so obvious when I looked at it again.

Too much linear thinking on my part in this case.

Your help was truly appreciated and very thorough.

George
 
Old 01-08-2012, 01:44 AM   #5
EricTRA
LQ Guru
 
Registered: May 2009
Location: Gibraltar, Gibraltar
Distribution: Fedora 20 with Awesome WM
Posts: 6,805
Blog Entries: 1

Rep: Reputation: 1296Reputation: 1296Reputation: 1296Reputation: 1296Reputation: 1296Reputation: 1296Reputation: 1296Reputation: 1296Reputation: 1296
Hello,

You're welcome although most credits go to T3RM1NVT0R for providing a step by step guide. I'm more of a 'point at it' guy since its my experience that you'll learn far more that way and what you learn will be remembered longer.

Thanks for marking the thread as solved. Have fun with Linux.

Kind regards,

Eric
 
Old 01-08-2012, 11:21 AM   #6
T3RM1NVT0R
Senior Member
 
Registered: Dec 2010
Location: Internet
Distribution: Linux Mint, SLES, CentOS, Red Hat
Posts: 2,385

Rep: Reputation: 477Reputation: 477Reputation: 477Reputation: 477Reputation: 477
@ Reply

You're welcome gjwalsh. Thanks for marking the thread as solved. Enjoy linux!!!

Thanks EricTRA, you're right a person learn when he do it himself.

Last edited by T3RM1NVT0R; 01-08-2012 at 11:22 AM.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
[SOLVED] search files and directories' owner windstory Linux - Newbie 1 06-04-2011 12:18 AM
using find to only search specific directories isaaclw Linux - Software 5 01-09-2010 08:01 AM
Search tools (Affinity, Tracker Search Tool, etc.) not working - don't find any files Adamantus Linux - Newbie 1 03-29-2009 11:21 PM
Search repo for files/directories by name with wget gnashley Programming 1 12-30-2007 05:13 AM
Search for files only in directories you have sufficient permissions tepez Linux - Software 1 04-08-2007 10:07 AM

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

All times are GMT -5. The time now is 03:44 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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration