user group shell script
I need a shell script that will print all users that belong to over 10 groups.
Currently I am getting the usernames from getent passwd, using awk get get the usernames, then running groups on each of the usernames. I have not figured out how I will count the groups yet but here is what I have so far. Code:
#!/bin/sh Thanks |
no file and a trick with IFS and read
any better? Code:
|
Hello mjhermanso21 :)
Code:
for user in $( awk -F":" '{ print $1 }' < /etc/passwd ) Charles |
Inspired by bigearsbilly's techniques ...
Code:
IFS=':' Code:
IFS=':' |
Thanks both of you. My only edit, which I didn't mention in my original post, was i wanted it to print like "user: groups...." so my final script was
#!/bin/sh for user in $( awk -F":" '{ print $1 }' < ./passwd.out ) do [[ $( groups $user | wc -w ) -gt 9 ]] && groups $user done *also we used LDAP not /etc/passwd so I am using a tmp file that has passwd info in it. |
Quote:
Code:
<command to write LDAP stuff to stdout> | while IFS=':' read user rest |
very nice. and more efficient too!
|
Quote:
|
All times are GMT -5. The time now is 01:08 PM. |