I have NO idea how portable this is, whether it would work in an environment other than my own, etc... So - give it a try, let me know if you found some place it would not work and how you fixed it.
This is a HACK. Someone could do this with Perl/Python/etc... and make lightwork of the problem. That was not a possible solution for what I was trying to do.
So - I would like to automate a job to take the users who belong to a particular netgroup and apply filesystem quotas to those users. Unfortunately, the output from a getent command is a bit difficult to simply parse.
I am going to create a file with the output of the getent command (not necessary)
[jradtke@cypher BashFoo]$ getent netgroup sysadmin > netgroup.sysadmin
sysadmin ( , jradtke, ) ( , usern1, ) ( , dilbert, )
Remove the name of the netgroup itself from my query
[jradtke@cypher BashFoo]$ cat netgroup.sysadmin | sed 's/sysadmin//g'
( , jradtke, ) ( , usern1, ) ( , dilbert, )
This next step is a total hack, I replace the the trailing parenthesis ) with a newline character
[jradtke@cypher BashFoo]$ cat netgroup.sysadmin | sed 's/sysadmin//g' | sed 's/)/\n/g'
( , jradtke,
( , usern1,
( , dilbert,
I then display the 2nd field using the comma ',' as my Field Seperator
[jradtke@cypher BashFoo]$ cat netgroup.sysadmin | sed 's/sysadmin//g' | sed 's/)/\n/g' | awk 'BEGIN {FS=","}{print $2}'
jradtke
usern1
dilbert
Lastly - I remove the leading space before each name
[jradtke@cypher BashFoo]$ cat netgroup.sysadmin | sed 's/sysadmin//g' | sed 's/)/\n/g' | awk 'BEGIN {FS=","}{print $2}' | grep -v ^$
jradtke
usern1
dilbert
[jradtke@cypher BashFoo]$ cat netgroup.sysadmin | sed 's/sysadmin//g' | sed 's/)/\n/g' | awk 'BEGIN {FS=","}{print $2}' | grep -v ^$ | sed 's/\ //g'
jradtke
usern1
dilbert
This is a HACK. Someone could do this with Perl/Python/etc... and make lightwork of the problem. That was not a possible solution for what I was trying to do.
So - I would like to automate a job to take the users who belong to a particular netgroup and apply filesystem quotas to those users. Unfortunately, the output from a getent command is a bit difficult to simply parse.
I am going to create a file with the output of the getent command (not necessary)
[jradtke@cypher BashFoo]$ getent netgroup sysadmin > netgroup.sysadmin
sysadmin ( , jradtke, ) ( , usern1, ) ( , dilbert, )
Remove the name of the netgroup itself from my query
[jradtke@cypher BashFoo]$ cat netgroup.sysadmin | sed 's/sysadmin//g'
( , jradtke, ) ( , usern1, ) ( , dilbert, )
This next step is a total hack, I replace the the trailing parenthesis ) with a newline character
[jradtke@cypher BashFoo]$ cat netgroup.sysadmin | sed 's/sysadmin//g' | sed 's/)/\n/g'
( , jradtke,
( , usern1,
( , dilbert,
I then display the 2nd field using the comma ',' as my Field Seperator
[jradtke@cypher BashFoo]$ cat netgroup.sysadmin | sed 's/sysadmin//g' | sed 's/)/\n/g' | awk 'BEGIN {FS=","}{print $2}'
jradtke
usern1
dilbert
Lastly - I remove the leading space before each name
[jradtke@cypher BashFoo]$ cat netgroup.sysadmin | sed 's/sysadmin//g' | sed 's/)/\n/g' | awk 'BEGIN {FS=","}{print $2}' | grep -v ^$
jradtke
usern1
dilbert
[jradtke@cypher BashFoo]$ cat netgroup.sysadmin | sed 's/sysadmin//g' | sed 's/)/\n/g' | awk 'BEGIN {FS=","}{print $2}' | grep -v ^$ | sed 's/\ //g'
jradtke
usern1
dilbert
Comments
Post a Comment