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.
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
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.