Linux - NewbieThis 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
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
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 08:07 AM.
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.
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?
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.
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
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 08:21 AM.
-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.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.