SlackwareThis Forum is for the discussion of Slackware Linux.
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.
Hello!
I am writing a SlackBuild script and in the doinst.sh file I need to create a user "someuser" and a group "somegroup" and then add that user to that group.
So far I figured out how to check if the user already exists:
if cat /etc/passwd | cut -f 1 -d : | grep -q someuser; then echo "there is someuser"; fi
whether the group exists:
if cat /etc/group | cut -f 1 -d : | grep -q someuser; then echo "there is somegroup"; fi
and whether the user someuser is a member of the group somegroup:
if groups someuser | grep -q somegroup; then echo "is a member";else echo "is not a member"; fi
The question is in case both the user and the group exist, but the user is not a member of the group, how do I add that user to that group. In short how do I add an existing user to an existing group?
Googling has suggested doing it by:
usermod -aG somegroup someuser
Unfortunately the usermod command on Slackware 12.0 does not support the -a option. I need the latter because I do not want to lose the other groups that someuser is a member of. Is there some other simple way of doing that?
Any suggestions will be appreciated.
Regards,
Martin
PS Let me know if the usermod command in Slackware 12.1 supports the -a option.
If you're writing this build script for SlackBuilds.org submission, don't bother to add the automatic group addition and such, as we'll just remove it. That needs to be documented in the README for the administrator to do.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.