In my script I need to find out whether user is in dialout group and if he is not, add him to the group. I have found out how to add him but is there a way how to know if he is in the group ?
You can do this in both ways:
Check all groups a specific user is member of and check if dialout
is there:
id username
Or as Wolf said already:
groups username
Check all members of the specific group (dialout
) and check if the user is in the list:
getent group dialout
You are looking for the groups
command. Here's an example of me using it on a server I just happened to be talking to at the moment (I'm logged in as the lprod
user):
[lprod@milazgit01 ~] $ groups wolf
wolf : prod tools
Then you can compare that to a regular expression in whatever shell you are using.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With