LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 08-04-2009, 05:52 AM   #1
stian
LQ Newbie
 
Registered: May 2009
Posts: 6

Rep: Reputation: 0
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
 
Old 08-04-2009, 06:17 AM   #2
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,417

Rep: Reputation: 1984Reputation: 1984Reputation: 1984Reputation: 1984Reputation: 1984Reputation: 1984Reputation: 1984Reputation: 1984Reputation: 1984Reputation: 1984Reputation: 1984
unrelated to networking. Moved to Linux - Newbie.
 
Old 08-04-2009, 06:19 AM   #3
ChrisAbela
Member
 
Registered: Mar 2008
Location: Malta
Distribution: Slackware
Posts: 572

Rep: Reputation: 154Reputation: 154
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
 
Old 08-04-2009, 06:30 AM   #4
stian
LQ Newbie
 
Registered: May 2009
Posts: 6

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by ChrisAbela View Post
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.
 
Old 08-04-2009, 06:36 AM   #5
stian
LQ Newbie
 
Registered: May 2009
Posts: 6

Original Poster
Rep: Reputation: 0
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
 
Old 08-04-2009, 06:36 AM   #6
ChrisAbela
Member
 
Registered: Mar 2008
Location: Malta
Distribution: Slackware
Posts: 572

Rep: Reputation: 154Reputation: 154
Excel Menu
File >> Save as >> Save as type (Choose txt)
 
Old 08-04-2009, 07:36 AM   #7
stian
LQ Newbie
 
Registered: May 2009
Posts: 6

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by ChrisAbela View Post
Excel Menu
File >> Save as >> Save as type (Choose txt)
I still dont understand what to do..
.bat script?
 
Old 08-04-2009, 12:11 PM   #8
f14f21
Member
 
Registered: Sep 2008
Distribution: rhel
Posts: 42

Rep: Reputation: 6
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
 
Old 08-04-2009, 12:43 PM   #9
stian
LQ Newbie
 
Registered: May 2009
Posts: 6

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by f14f21 View Post
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
 
Old 08-04-2009, 12:51 PM   #10
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,417

Rep: Reputation: 1984Reputation: 1984Reputation: 1984Reputation: 1984Reputation: 1984Reputation: 1984Reputation: 1984Reputation: 1984Reputation: 1984Reputation: 1984Reputation: 1984
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
 
Old 08-04-2009, 02:05 PM   #11
stian
LQ Newbie
 
Registered: May 2009
Posts: 6

Original Poster
Rep: Reputation: 0
ye, i figured out.

its working perfectly. thanks.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
How do I change a user's primary group? Akhran Linux - Newbie 4 03-19-2010 08:54 PM
what is primary group ram_rajavarapu Linux - Enterprise 2 01-23-2009 08:32 AM
Script to change routes when primary net connection dies koflanagan Linux - Software 0 05-19-2006 04:25 PM
Script - Find primary group quack322 Programming 3 01-02-2005 04:13 AM
What is a Primary Group? ejtbrown Linux - General 2 03-21-2001 04:14 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 02:44 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration