ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
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
but what i wanted to do is take the output
of this command
groups $uzr | cut -f4,5,6 -d \ ;
then assign it with $x , $z
$1 = a group name i added in the script
usermod -G $1,$x,$z $uzr
The Script Is That...
____________________
#!bin/bash
#creating a group then assigning all users to it ....
groupadd $1
cd /home && echo "Making $1 Directory"
mkdir -m 3770 $1 ;
chgrp $1 $1
cd /home/$1
for uzr in `grep /home /etc/passwd | cut -f 1 -d :`
do
groups $uzr | cut -f4,5,6 -d \ ;
"(the problem here)..assign the output (the fields i catted)from the previous line
to $x,$o,$j and so forth....to prevent deleting users from old-groups when i creat
a new one...
usermod -G $1,$x,$o,$j $uzr
mkdir -p -m 3770 $uzr"_dir"
done
echo "Users Has Been Added To $1 Group"
_______________________________________________
If I were you, I would avoid put all users from /etc/passwd in a new created group,
I woul make a limited users list instead...
For the loop I would do :
Code:
# I follow your wish, all users from passwd
userslist=`cat /etc/passwd | cut -d: -f1`
for user in $userslist; do
# all $user groups
groups=`id $user -Gn`
# all groups, coma separated
groups=`echo $groups | sed -e 's/ /,/g'`
# remove echo if you're satisfied
echo "usermod -G $1,$groups $user"
echo "mkdir -p -m 3770 $user_dir"
done
Originally posted by keefaz If I were you, I would avoid put all users from /etc/passwd in a new created group,
I woul make a limited users list instead...
Why? There are plenty of situations where this would be not only perfectly acceptable but the only possible means to an end.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.