Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

using one variable with multiple patterns 1

Status
Not open for further replies.

w5000

Technical User
Nov 24, 2010
223
0
0
PL

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 .
# [blue][bold]ls file????|wc[/blue][/bold]
    4096    4096   36864
# [blue][bold]ls -al file????|awk '$1$2~/^-r.x......nobody$/||$1$4~/^-...r.x...system$/||$1~/^-......r.x$/'|tail -5[/blue][/bold]
-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
# [blue][bold]ls -al file????|awk '$1$2~/^-r.x......nobody$/||$1$4~/^-...r.x...system$/||$1~/^-......r.x$/'|wc -l[/blue][/bold]
     960
# [blue][bold]chgrp cron file5777[/blue]
#
# [blue][bold]ls -al file????|awk '$1$2~/^-r.x......nobody$/||$1$4~/^-...r.x...system$/||$1~/^-......r.x$/'|wc -l[/blue][/bold]
     959
# [blue][bold]lsuser -a groups root|awk -F= '{print $NF}'|sed s/,/\|/g[/blue][/bold]
[red]system|bin|sys|security|cron|audit|lp|idsldap|idsldag[/red]
# [blue][bold]ls -al file????|awk '$1$2~/^-r.x......nobody$/||$1$4~/^-...r.x...([/blue][red]system|bin|sys|security|cron|audit|lp|idsldap|idsldag[/red][blue])$/||$1~/^-......r.x$/'|wc -l[/blue][/bold]
     960
 
One way:
Code:
groups=$(lsuser -a groups root|awk -F= '{print $NF}'|sed s/,/\|/g)
ls -al file????|awk '$1$2~/^-r.x......nobody$/||$1$4~/^-...r.x...('"$groups"')$/||$1~/^-......r.x$/'|wc -l

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 

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
#
 

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

Code:
# find ./file???? \( [red][bold]\([/bold] \( $(lsuser -a groups root|awk -F= '{print $NF}'|sed 's/,/\ \-o\ \-group\ /g;s/^/\ \-group\ /') \) -a -perm -g+rx [bold]\)[/bold][/red] -o [blue][bold]\([/bold] -user root -a -perm -u+rx [bold]\)[/bold][/blue] -o [green][bold]\([/bold] -perm -o+rx [bold]\)[/bold] \)[/green] -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
#
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top