Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

Let's assume I have a Linux box configured as a primary domain controller with 50 users connecting at any given time. If I wanted to create two groups, one called "Teachers" and the other "Students" How could I script something so I wouldn't have to individually type out each command for each user when adding them to their appropriate group?

This is what scripting is all about yes?

share|improve this question
add comment

2 Answers

up vote 2 down vote accepted

A loop in this format will work:

while read i ; do 
    command_name "$i"
done < filename

The file named filename would contain a list of users, one per line. For the command name command_name use useradd -G {group-name}.

share|improve this answer
add comment

Change group1 and group2 to your desired groups, and use -M user1,user2,user3,... as the users.

for group in group1 group2
do gpasswd -M user1,user2,... $group
done
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.