×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

using one variable with multiple patterns

using one variable with multiple patterns

using one variable with multiple patterns

(OP)

hello,
I need to check if files +rx by user or at least by members of group user belongs to or by other world.
I have created list of files with complete 4096 permission possibilities.
How to pass all groups user is member of (marked in red) to the last awk command using variable?

CODE

# chown root .;chmod 700 .
# ls file????|wc
    4096    4096   36864
# ls -al file????|awk '$1$2~/^-r.x......nobody$/||$1$4~/^-...r.x...system$/||$1~/^-......r.x$/'|tail -5
-rwsr-srwx    1 root     system            0 Dec 06 14:39 file6757
-rwsrwSr-x    1 root     system            0 Dec 06 14:39 file6765
-rwsrwSrwx    1 root     system            0 Dec 06 14:39 file6767
-rwsrwsr-x    1 root     system            0 Dec 06 14:39 file6775
-rwsrwsrwx    1 root     system            0 Dec 06 14:39 file6777
# ls -al file????|awk '$1$2~/^-r.x......nobody$/||$1$4~/^-...r.x...system$/||$1~/^-......r.x$/'|wc -l
     960
# chgrp cron file5777
#
# [bold]ls -al file????|awk '$1$2~/^-r.x......nobody$/||$1$4~/^-...r.x...system$/||$1~/^-......r.x$/'|wc -l
     959
# lsuser -a groups root|awk -F= '{print $NF}'|sed s/,/\|/g
system|bin|sys|security|cron|audit|lp|idsldap|idsldag
# ls -al file????|awk '$1$2~/^-r.x......nobody$/||$1$4~/^-...r.x...(system|bin|sys|security|cron|audit|lp|idsldap|idsldag)$/||$1~/^-......r.x$/'|wc -l
     960 

RE: using one variable with multiple patterns

(OP)

would such be a 'solution' / and better way to find the files?

CODE

# find ./file???? \( $(lsuser -a groups root|awk -F= '{print $NF}'|sed 's/,/\ \-o\ \-group\ /g;s/^/\ \-group\ /') \) -a \( -perm -o+rx -o -perm -u+rx -o -perm -g+rx \)|wc
    2368    2368   26048
# find ./file???? \( \( $(lsuser -a groups root|awk -F= '{print $NF}'|sed 's/,/\ \-o\ \-group\ /g;s/^/\ \-group\ /') \) -a \( -perm -o+rx -o -perm -u+rx -o -perm -g+rx \) \)|wc
    2368    2368   26048
# 

RE: using one variable with multiple patterns

(OP)

thank you.
/the way with find seems to work as well/

CODE

# find ./file???? \( \( \( $(lsuser -a groups root|awk -F= '{print $NF}'|sed 's/,/\ \-o\ \-group\ /g;s/^/\ \-group\ /') \) -a -perm -g+rx \) -o \( -user root -a -perm -u+rx \) -o \( -perm -o+rx \) \) -ls|wc
    2368   26048  187072
# chmod ugo-rx file????
# find ./file???? \( \( \( $(lsuser -a groups root|awk -F= '{print $NF}'|sed 's/,/\ \-o\ \-group\ /g;s/^/\ \-group\ /') \) -a -perm -g+rx \) -o \( -user root -a -perm -u+rx \) -o \( -perm -o+rx \) \) -ls|wc
       0       0       0
# chmod g+r ./file7775
# find ./file???? \( \( \( $(lsuser -a groups root|awk -F= '{print $NF}'|sed 's/,/\ \-o\ \-group\ /g;s/^/\ \-group\ /') \) -a -perm -g+rx \) -o \( -user root -a -perm -u+rx \) -o \( -perm -o+rx \) \) -ls|wc
       0       0       0
# chmod g+rx ./file7775
# find ./file???? \( \( \( $(lsuser -a groups root|awk -F= '{print $NF}'|sed 's/,/\ \-o\ \-group\ /g;s/^/\ \-group\ /') \) -a -perm -g+rx \) -o \( -user root -a -perm -u+rx \) -o \( -perm -o+rx \) \) -ls|wc
       1      11      79
# lsuser -a groups root|awk -F= '{print $NF}'
system,bin,sys,security,cron,audit,lp,idsldap,idsldag
# chgrp apache ./file7775
# find ./file???? \( \( \( $(lsuser -a groups root|awk -F= '{print $NF}'|sed 's/,/\ \-o\ \-group\ /g;s/^/\ \-group\ /') \) -a -perm -g+rx \) -o \( -user root -a -perm -u+rx \) -o \( -perm -o+rx \) \) -ls|wc
       0       0       0
# chmod o+rx ./file7775
# find ./file???? \( \( \( $(lsuser -a groups root|awk -F= '{print $NF}'|sed 's/,/\ \-o\ \-group\ /g;s/^/\ \-group\ /') \) -a -perm -g+rx \) -o \( -user root -a -perm -u+rx \) -o \( -perm -o+rx \) \) -ls|wc
       1      11      79
# 

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close