SlackwareThis Forum is for the discussion of Slackware Linux.
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.
Introduction to Linux - A Hands on Guide
This guide was created as an overview of the Linux Operating System, geared toward new users as an exploration tour and getting started guide, with exercises at the end of each chapter.
For more advanced trainees it can be a desktop reference, and a collection of the base knowledge needed to proceed with system and network administration. This book contains many real life examples derived from the author's experience as a Linux system and network administrator, trainer and consultant. They hope these examples will help you to get a better understanding of the Linux system and that you feel encouraged to try out things on your own.
Click Here to receive this Complete Guide absolutely free.
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.
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.