Need some help writing a find script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Need some help writing a find script
# 1  
Old 03-17-2012
Need some help writing a find script

hello all!
well, here is my problem:
i have to write a script which waits for a directory as an argument and scans it recuresively and than it prints those files, which have write permission for everyone (as relative path from the argument directory so the find will be the key). and it shouldnt print those files which have write permissions for everyone but they couldnt be writed (their parent directory dont have execution permission for the others)

(sorry for my bad english)
# 2  
Old 03-17-2012
What OS are you on - waiting for a directory can mean a lot of different things depending on the OS. What shell are you using? (like bash, ksh, etc.)
# 3  
Old 03-17-2012
ubuntu and bash

heres a little example

Code:
$ls -lR /home/example 
/home/example: 
total 8 
drwxrwxr-x 2 example users 4096 2009-01-31 00:00 directory1 
drwxrwx--- 2 example users 4096 2009-01-31 00:00 directory2 
-rw-rw-rw- 1 example users    0 2009-01-31 00:00 first.txt 
 
/home/h123456/directory1: 
total 0 
-rw-rw-rw- 2 example users    0 2009-01-31 00:00 aaa.txt 
-rw-rw-r-- 2 example users    0 2009-01-31 00:00 bbb.txt 
 
/home/h123456/directory2: 
total 0 
-rw-rw-rw- 2 example users    0 2009-01-31 00:00 ccc.txt 

$ ./prog.sh /home/example
first.txt 
directory1/aaa.txt

# 4  
Old 03-17-2012
Exactly what you mean by 'waiting for a directory' is still unclear. Assuming that as soon as a directory exists, all files below are present, might not be wise, or correct, and thus the results of a search at time t might not be the same as a search at time t+n.

Assuming the directory exists, and is in a stable/steady state, this will find the files you are looking for. It should handle filenames with spaces, but will not handle directory names with spaces. The other assumption is that all directories/files below a directory that has an executable bit turned off for the world (other) excludes it, and anything below it, from the search.

Code:
dname="${1:-.}"
while [[ ! -d $dname ]]    # simple wait for the directory to exist -- may not be enough to be correct
do
    sleep 10
done

find $dname -ls | awk '
    {
        split( $3, perms, "" );

        if( dname && index( $11, dname ) == 1 )
            next;
        else
            dname = ""

        if( perms[1] == "d" )
        {
            if( perms[10] == "-" )      # execute for directory is off for world, can be skipped
                dname = $11 "/";
        }
        else
            if( perms[9] == "w" )
                print;
    }
'

# 5  
Old 03-17-2012
forget that waiting for the directory thing, i just want to say that i have to specify a directory as an argument when i execute it.

and i forget that, i have to make it without awk :S
# 6  
Old 03-17-2012
Quote:
Originally Posted by Mixe3y
and i forget that, i have to make it without awk :S
It certainly would have been nice to have had all parameters and/or limitations in your initial post.

With the 'no awk' requirement this seems more like a homework assignment than not. Maybe, before anybody else spends time crafting a solution, you should indicate whether it's a homework assignment or not.
# 7  
Old 03-17-2012
its a simple homework :S

---------- Post updated at 12:30 PM ---------- Previous update was at 12:24 PM ----------

well, sorry for the misinformation again,
my mate just told me our teacher let us use awk
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

I need help writing this script

:wall: Can't seem to figure out how to fix this please help its not starting over like I would like it to When I enter in "Date" or "Time" nothing comes Also if you can tell me the commands for the other 3 stuff that would be much appreciated #!/bin/bash clear while ; do echo... (8 Replies)
Discussion started by: nowruzr
8 Replies

2. Shell Programming and Scripting

how to find a job which is writing a big file and eating up space?

how to find a job which is writing a big file and eating up space? (3 Replies)
Discussion started by: rush2andy
3 Replies

3. Shell Programming and Scripting

Help in writing a find/replace script using awk

Hi All, I need to write a script that will go through 600+ files and perform find and replace. I was going to use sed but there is a level of complexity that is doing my head in. To explain: I have 600+ files that have a line in them that reads (for example) FILE=DCLCLHST... (4 Replies)
Discussion started by: Kocko
4 Replies

4. Shell Programming and Scripting

writing shell script to find line of invalid characters

Hi, I have to write s script to check an input file for invalid characters. In this script I have to find the exact line of the invalid character. If the input file contain 2 invalid character sat line 10 and 17, the script will show the value 10 and 17. Any help is appreciated. (3 Replies)
Discussion started by: beginner82
3 Replies

5. UNIX for Dummies Questions & Answers

Help writing a script to find a file

I just started learning about Unix and I cant figure out what im doing wrong. I'm trying to write a script that will ask for the file name and tell what type it is. This is what i have so far. http://i63.photobucket.com/albums/h123/wacand/untitled.jpg (2 Replies)
Discussion started by: wacand
2 Replies

6. Shell Programming and Scripting

Help me in writing the script

Hi, I have written a script which converts a give hexdecimal value to binary value in perl. But now, the problem is I should read every bit of it ( if its 10101010, i should read the value in each position and if the value in that position is 1 i should print a string and should exit if its... (1 Reply)
Discussion started by: prakashreddy
1 Replies

7. UNIX for Dummies Questions & Answers

Need help writing this script

Here is the script I am trying to write along with my answer I wrote. Please help me understand why it doesn't work. Create an executable script file called "newname" that will perform the followings: 1. Rename a file upon the user's request. If the file exists, prompt the user for... (1 Reply)
Discussion started by: wiggles
1 Replies

8. UNIX for Dummies Questions & Answers

how to find out the systen and n/w charecteristics by writing codes in c

a project is given to me in which i have to find out the system and n/w charecteristics by writing codes in c but i cant use the commands. n/w charecteristics means: Network Adapter Related Information: a. Number of network adapters b. Type of the Adapter: LAN (Ethernet, Token Ring, FDDI),... (8 Replies)
Discussion started by: jeenat
8 Replies

9. UNIX for Dummies Questions & Answers

help for writing a script

Hi, I need help writing a unix script to change the time in the server automatically when it reaches a specified time. Only on the 14th of april, when the time becomes midnight (00:00:00), I need the server to change the time automatically to 23:30:00 and start working on as usual with a... (2 Replies)
Discussion started by: amodha
2 Replies

10. Shell Programming and Scripting

need help writing a script

Hello everyone. Well, I will get right to the point. I am new to Perl and trying to learn it as much as I can. I have been assigned the task of writing a perl script to extract information from firewall logs. Like I said, I am new to Perl and I am having a tough time because I think what I am... (3 Replies)
Discussion started by: tarballed
3 Replies
Login or Register to Ask a Question