LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   script to change primary group. (https://www.linuxquestions.org/questions/linux-newbie-8/script-to-change-primary-group-744991/)

stian 08-04-2009 05:52 AM

script to change primary group.
 
Hey,

I need an script to change primary group. Got a linuxbox running ldap + samba.

Do anybody got any tips on why I can make this script? It is about 400 user.

please help

acid_kewpie 08-04-2009 06:17 AM

unrelated to networking. Moved to Linux - Newbie.

ChrisAbela 08-04-2009 06:19 AM

I assume that you have a list of users called users_list. You may get a copy of /etc/passwd and manipulate it with sed or awk to compile the list.

Quote:

#!/bin/sh
for i in `cat users_list`
do
usermod -g new_initial_group $i
done
Chris

stian 08-04-2009 06:30 AM

Quote:

Originally Posted by ChrisAbela (Post 3630677)
I assume that you have a list of users called users_list. You may get a copy of /etc/passwd and manipulate it with sed or awk to compile the list.



Chris

probly a stupid question, but where do i find the "user_list" ?

The problem is that i have 400 user who should have different primarygroup.

I got alle the usernames + password etc in an excel file.

stian 08-04-2009 06:36 AM

A little more information:

The users downunder her, I want their primarygroup to be "tbu"

username

ou=Teachers,ou=Users,dc=skole,dc=lk,dc=local uid l513
ou=Teachers,ou=Users,dc=skole,dc=lk,dc=local uid l514
ou=Teachers,ou=Users,dc=skole,dc=lk,dc=local uid l516
ou=Teachers,ou=Users,dc=skole,dc=lk,dc=local uid l518



But i want these users to have primary group "tau"
LXXX = username

ou=Teachers,ou=Users,dc=skole,dc=lk,dc=local uid l320
ou=Teachers,ou=Users,dc=skole,dc=lk,dc=local uid l321
ou=Teachers,ou=Users,dc=skole,dc=lk,dc=local uid l324
ou=Teachers,ou=Users,dc=skole,dc=lk,dc=local uid l326
ou=Teachers,ou=Users,dc=skole,dc=lk,dc=local uid l327
ou=Teachers,ou=Users,dc=skole,dc=lk,dc=local uid l328
ou=Teachers,ou=Users,dc=skole,dc=lk,dc=local uid l329
ou=Teachers,ou=Users,dc=skole,dc=lk,dc=local uid l330
ou=Teachers,ou=Users,dc=skole,dc=lk,dc=local uid l333

ChrisAbela 08-04-2009 06:36 AM

Excel Menu
File >> Save as >> Save as type (Choose txt)

stian 08-04-2009 07:36 AM

Quote:

Originally Posted by ChrisAbela (Post 3630699)
Excel Menu
File >> Save as >> Save as type (Choose txt)

I still dont understand what to do..
.bat script?

f14f21 08-04-2009 12:11 PM

make file with vi editor named /solution.sh as ChrisAbela said and write following codes on
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#!/bin/sh
for i in `cat users_list`
do
usermod -g new_initial_group $i
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
make file with vi editor named /users_list and write following (add ur usernames ) :

nancy
mohammad
naser
fredrick
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

#./solution.sh

stian 08-04-2009 12:43 PM

Quote:

Originally Posted by f14f21 (Post 3631160)
make file with vi editor named /solution.sh as ChrisAbela said and write following codes on
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#!/bin/sh
for i in `cat users_list`
do
usermod -g new_initial_group $i
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
make file with vi editor named /users_list and write following (add ur usernames ) :

nancy
mohammad
naser
fredrick
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

#./solution.sh

thank you!

root@ma01:~# /etc/script/set_primary_group.sh
-bash: /etc/script/set_primary_group.sh: Permission denied


Got tips for that to ? :P

acid_kewpie 08-04-2009 12:51 PM

Why are you putting scripts in /etc?? Very bad place for them.

mv /etc/script/set_primary_group.sh /root/
chmod +x /root/set_primary_group.sh
/root/set_primary_group.sh

stian 08-04-2009 02:05 PM

ye, i figured out.

its working perfectly. thanks.


All times are GMT -5. The time now is 05:20 AM.