Linux - NewbieThis Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place!
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Thanks for your reply, I found that when trying to do
For example
useradd -g support tim
And I go and look at the file /etc/group, the user "tim" was not added to the end of the group line, like this:
support:x:1001:
It means that the useradd command didn't update /etc/group file eventhough if I issue the command:
groups tim => it does show it belongs to the group "support"
And that's why your command doesn't work. Do you have any ideas why it doesn't update the group file ???
I'm logged in as root user, using Ubuntu 7.10 Desktop ed.
There is a possibility that the group in question is a users primary group. You need to check the /etc/group file and the /etc/passwd if you want to be 100% sure. To my knowledge there is no command to do this, you need to write it yourself.
The fact that the group is represented as a number in the /etc/passwd file makes this a bit harder.
You need to:
1) get the number from the /etc/group file (and also get the users attached to it)
2) check to see if the found group number is present in the /etc/passwd file.
Something like this (rough example):
Code:
#!/bin/bash
srchGroup="$1"
# get the corresponding line from /etc/group
for thisLine in "`grep "^${srchGroup}:" /etc/group`"
do
# get the parts of interest
grpNumber="`echo ${thisLine} | cut -d":" -f3`"
grpUsers="`echo ${thisLine} | cut -d":" -f4 | sed 's/,/ /g'`"
done
# check /etc/passwd
pwdUsers="`awk -F":" '$4 ~ /'${grpNumber}'/ { printf("%s ",$1) }' /etc/passwd`"
echo "0 ${srchGroup}" # given at commandline
echo "1 ${grpNumber}" # from /etc/group
echo "2 ${grpUsers}" # from /etc/group
echo "3 ${pwdUsers}" # from /etc/passwd
echo "All users: ${grpUsers} ${pwdUsers}"
Example run:
Code:
$ ./show.group.users internet
0 internet
1 500
2 testuser anotheruser
3 druuna jade
All users: testuser anotheruser druuna jade
PS: I just noticed your previous reply, you already noticed the passwd file part
I'm posting this reply as I found this answer when Google searching but all the answers given are lacking something. Reading /etc/group and /etc/passwd directly is not portable as systems can use other authentication mechanisms. Also the Bash script given is a bit wordy and it has a bug matching the group number so if you ask for users in group 0 you get users in group 100 101 1000 etc.
Other forums have Perl scripts and any number of other suggestions, but Perl is a bit of a sledgehammer to crack a nut.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.