LinuxQuestions.org
Register a domain and help support LQ
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 12-02-2005, 09:05 AM   #1
curious+cat
LQ Newbie
 
Registered: Dec 2005
Posts: 6

Rep: Reputation: 0
"Find" command


Hello all,
I'm trying to edit a script that is running on AIX 5.1, that goes below :

Code:
files=". .bashrc .bash_login .bash_logout .bash_profile .cshdirs .cshrc .custom.cshrc .custom.kshrc .custom.login .custom.profile .dmrc .first_start_kde .forward .gconf .gconfd .gnome .gnome_private .gnome2 .gnome2_private kde .kde .kde/Autostart .kderc .login .logout .nodes .profile .qt .qt/qtrc .tcsh
rc .vnc .vnc/passwd .vnc/xstartup .Xauthority .xdefaults .xresources .xstartup .x screensaver .xsession .zshenv .zshrc .zlogin .zlogout"

 illegal="`eval find $files -prune '\(' ! -user $user -a ! -user root '\)' \
                -o '\(' ! -group $group -a ! -group root -a -perm -020 '\)' \
                -o $perm 2>/dev/null`"
    if [ -n "$illegal" ]; then
        log "<warn> rule 2600: files with illegal owner or permission found for "
 \
            "user $user: "$illegal"."
        if [ "$enforce" = "1" ]; then
            for fi in $illegal; do
                debug "Change permissions file $fi to $mode."
                chmod "$mode" "$fi"
                debug "Mode change status: $?."
            done
        fi
    fi

The 'find' command unfortunately do not work in AIX, because it was trying to get output from 'files' and it was more than one filename in there. The error I got was :

find: 0652-009 There is a missing conjunction

Any idea how I can fix the scripts so the find command can work with multiple files?

Thanks in advance.

- Suze

Last edited by curious+cat; 12-02-2005 at 09:07 AM.
 
Old 12-02-2005, 09:17 AM   #2
MensaWater
LQ Guru
 
Registered: May 2005
Location: Atlanta Georgia USA
Distribution: Redhat (RHEL), CentOS, Fedora, Debian, FreeBSD, HP-UX, Solaris, SCO
Posts: 6,679
Blog Entries: 14

Rep: Reputation: 1021Reputation: 1021Reputation: 1021Reputation: 1021Reputation: 1021Reputation: 1021Reputation: 1021Reputation: 1021
I'd be really surprised if "find" didn't work in AIX. It is one of the basic tools of Unix/Linux.

Anyway usually "missing conjunction" is just a cute way to tell you to put your search pattern in quotes:


find / -name *suze* = Missing conjuntion (not just on AIX)

find / -name "*suze*" = Any file with suze embedded in its name.

I've never figured out exactly what makes find complain about missing conjunction but long ago figured out the quotes told it to shut up about it. It has to do with the metacharacters but on occasion find blithely does the search without the quotes so go figure.

Memories of Scholastic Rock:

Conjuntion junction what's your function....
 
Old 12-02-2005, 09:21 AM   #3
curious+cat
LQ Newbie
 
Registered: Dec 2005
Posts: 6

Original Poster
Rep: Reputation: 0
Hi
Thanks for replying!

Yes, find does work in AIX but usually when I try to find a file (for example, .bashrc) , I do the following :

find /dir -name .bashrc - print

but since in the script it was taking the filename(s) from the variable $files (which has more than 1 filename in it, many files infact), it failed. Hopefully anyone out there might know a
way how I can get find to find multiple files at one go?

Sorry if I wasnt clear before!

Suze
 
Old 12-02-2005, 09:59 AM   #4
MensaWater
LQ Guru
 
Registered: May 2005
Location: Atlanta Georgia USA
Distribution: Redhat (RHEL), CentOS, Fedora, Debian, FreeBSD, HP-UX, Solaris, SCO
Posts: 6,679
Blog Entries: 14

Rep: Reputation: 1021Reputation: 1021Reputation: 1021Reputation: 1021Reputation: 1021Reputation: 1021Reputation: 1021Reputation: 1021
Well you could use the "-o" flag for or:

find / -name .bashrc -o -name .bash (etc...)

But that would be fairly unwieldy. If it were me I'd just pipe find through egrep:

find / |egrep ".bash|.login|..." - In egrep the pipe sign (|) means "or" - you have to encapsulae the list in quotes. (You only need .bash - not .bashrc as .bash will match both.

If your list needs to be unique you can look at what find / gives you then insure the pattern you put in the quotes is unique e.g.
".bash$|.bashrc$|..."

The $ tells it to find those names at the end of a line so it won't mach anything that's just embedded in another file name.

Note that in the above the elipses (...) mean add more patterns - you don't actually type the elipses but rather the addtional patterns.
 
Old 12-05-2005, 08:48 AM   #5
curious+cat
LQ Newbie
 
Registered: Dec 2005
Posts: 6

Original Poster
Rep: Reputation: 0
Thanks for your reply J! I find it very useful, that's a nice trick of 'find' command.

I was just wondering..I couldnt figure out yet if I can use the 'find' command to somehow get the filenames from the variable files in the script below :

Code:
files=". .bashrc .bash_login .bash_logout .bash_profile .cshdirs .cshrc .custom.cshrc .custom.kshrc .custom.login .custom.profile .dmrc .first_start_kde .forward .gconf .gconfd .gnome .gnome_private .gnome2 .gnome2_private kde .kde .kde/Autostart .kderc .login .logout .nodes .profile .qt .qt/qtrc .tcsh
rc .vnc .vnc/passwd .vnc/xstartup .Xauthority .xdefaults .xresources .xstartup .x screensaver .xsession .zshenv .zshrc .zlogin .zlogout"

 illegal="`eval find $files -prune '\(' ! -user $user -a ! -user root '\)' \
                -o '\(' ! -group $group -a ! -group root -a -perm -020 '\)' \
                -o $perm 2>/dev/null`"
    if [ -n "$illegal" ]; then
        log "<warn> rule 2600: files with illegal owner or permission found for "
 \
            "user $user: "$illegal"."
        if [ "$enforce" = "1" ]; then
            for fi in $illegal; do
                debug "Change permissions file $fi to $mode."
                chmod "$mode" "$fi"
                debug "Mode change status: $?."
            done
        fi
    fi
I tried using find / |egrep $files bla bla but it didnt work

Any ideas? Thanks in advance.
 
Old 12-05-2005, 09:19 AM   #6
MensaWater
LQ Guru
 
Registered: May 2005
Location: Atlanta Georgia USA
Distribution: Redhat (RHEL), CentOS, Fedora, Debian, FreeBSD, HP-UX, Solaris, SCO
Posts: 6,679
Blog Entries: 14

Rep: Reputation: 1021Reputation: 1021Reputation: 1021Reputation: 1021Reputation: 1021Reputation: 1021Reputation: 1021Reputation: 1021
egrep requries your patterns to be separated by pipe sign (|) rather than space. You'd have to define your variable with the pipe signs in it:

files=".bashrc|.bash_login|.bash_logout|.bash_profile|.cshdirs .cshrc|.custom.cshrc|.custom.kshrc|.custom.login|.custom.profile|.dmrc .first_start_kde|.forward|.gconf|.gconfd|.gnome|.gnome_private|.gnome2 .gnome2_private|kde|.kde|.kde/Autostart|.kderc|.login|.logout|.nodes .profile|.qt|.qt/qtrc|.tcsh|rc|.vnc|.vnc/passwd|.vnc/xstartup|.Xauthority |.xdefaults|.xresources|.xstartup|.xscreensaver|.xsession|.zshenv|.zshrc .zlogin|.zlogout"

Of course | has special meaning to the shell so its possible you'd need to escape it (put backslash in front of each occurrence). Just try it as aboove first.

Also remember grep (and egrep which is same as grep -E) matches any part of something so you don't need everything you have above. For example:

egrep kde

would find all of start_kde, kde, .kde, .kde/Autostart, .kderc from your original list so there's no reason to include all of those - just kde. NOTE: It will also find anything else that had kde in it such as other files under .kde/. To restrict it you'd have to use the end of line ($) special character for each:

kde$ start_kde$ .,kde/Autostart$ .kderc$

Even there the kde$ would find BOTH kde and .kde so you'd have to prepend it with start of line (^) special character - be careful on that though as doing a find usually prepends your search path so you'd have to put the start of line in front of the path.

Example: If "find ." it would put "./" in front of all entries so you'd have to do:

^./kde$ ^./.kde$

Last edited by MensaWater; 12-05-2005 at 09:21 AM.
 
Old 12-05-2005, 09:37 AM   #7
curious+cat
LQ Newbie
 
Registered: Dec 2005
Posts: 6

Original Poster
Rep: Reputation: 0
Thanks for the reply! Much clearer now, you are very kind.

This works :

find . | egrep ".bashrc|.bash_login"

But I dont know how to use them with -prune I tried this :

find . | egrep ".bashrc|.bash_login" -prune

But it says :

egrep: 0652-033 Cannot open -prune.

I am hopeless..help!

Thanks again.
 
Old 12-05-2005, 09:51 AM   #8
MensaWater
LQ Guru
 
Registered: May 2005
Location: Atlanta Georgia USA
Distribution: Redhat (RHEL), CentOS, Fedora, Debian, FreeBSD, HP-UX, Solaris, SCO
Posts: 6,679
Blog Entries: 14

Rep: Reputation: 1021Reputation: 1021Reputation: 1021Reputation: 1021Reputation: 1021Reputation: 1021Reputation: 1021Reputation: 1021
-prune is an argument to find not to grep or egrep. Since you piped your find into egrep you can't put -prune at the end because it thinks you're giving it as an argument to egrep at that point.
 
  


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
Shell Script: Find "Word" Run "Command" granatica Linux - Software 5 07-25-2007 08:42 AM
Not able to Run/find "configure" command aaryan72 Linux - Newbie 4 09-10-2005 12:16 PM
Warning on running "find" command satimis Linux From Scratch 1 08-06-2005 12:45 PM
Can't install "glibmm" library. "configure" script can't find "sigc++-2.0&q kornerr Linux - General 4 05-10-2005 03:32 PM
Help,I can't find my USB mouse when I run "kudzu" command in RH9. aeolus Red Hat 0 03-27-2004 10:14 PM


All times are GMT -5. The time now is 09:17 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