LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Server
User Name
Password
Linux - Server This forum is for the discussion of Linux Software used in a server related context.

Notices


Reply
  Search this Thread
Old 06-28-2009, 11:23 AM   #1
Tekken
Member
 
Registered: Jun 2009
Posts: 48

Rep: Reputation: 15
Script to add a secondary group to all users except system default users


Hi,

Can any one help me with a script which can add a secondary group to all existing users except system users in linux.
 
Old 06-29-2009, 03:26 AM   #2
JulianTosh
Member
 
Registered: Sep 2007
Location: Las Vegas, NV
Distribution: Fedora / CentOS
Posts: 674
Blog Entries: 3

Rep: Reputation: 90
grep ":5[0-9]\{2\}:" /etc/group | sed "s/:$/:newgroup/"
 
Old 06-29-2009, 06:15 AM   #3
Tekken
Member
 
Registered: Jun 2009
Posts: 48

Original Poster
Rep: Reputation: 15
Hi Admiral,

Thanks for your reply, Could you please post me a shell or Perl script if you have any for this purpose.
 
Old 06-29-2009, 06:36 AM   #4
JulianTosh
Member
 
Registered: Sep 2007
Location: Las Vegas, NV
Distribution: Fedora / CentOS
Posts: 674
Blog Entries: 3

Rep: Reputation: 90
Code:
#!/bin/bash

if [ $# -lt 1 ]; then
  echo Description:
  echo   Modifies /etc/group to add specified group to 'normal' users.
  echo   You must redirect output back into /etc/group if you're satisfied
  echo   with the results.
  echo
  echo Usage: $0 [ group ]
  echo
  echo
  exit
fi

sed "s/:\(5[0-9]\{2\}\):/:\1:$1,/" /etc/group
minor fix included.
 
Old 06-29-2009, 01:07 PM   #5
Tekken
Member
 
Registered: Jun 2009
Posts: 48

Original Poster
Rep: Reputation: 15
Quote:
Originally Posted by Admiral Beotch View Post
Code:
#!/bin/bash

if [ $# -lt 1 ]; then
  echo Description:
  echo   Modifies /etc/group to add specified group to 'normal' users.
  echo   You must redirect output back into /etc/group if you're satisfied
  echo   with the results.
  echo
  echo Usage: $0 [ group ]
  echo
  echo
  exit
fi

sed "s/:\(5[0-9]\{2\}\):/:\1:$1,/" /etc/group
minor fix included.
Hi,

I've tried using this by creating a new group and running this script by specifying the group as argument, but i was unable to see the secondary group information for user in the system.I want to create a group and after that by running the script it should make the newly created group as secondary group to all existing users except the system default user.
Could you please help me here....

Thanks in advance
 
Old 06-29-2009, 04:02 PM   #6
JulianTosh
Member
 
Registered: Sep 2007
Location: Las Vegas, NV
Distribution: Fedora / CentOS
Posts: 674
Blog Entries: 3

Rep: Reputation: 90
Code:
#!/bin/bash

if [ $# -lt 1 ]; then
  echo Description:
  echo   "Modifies /etc/group to add specified group to 'normal' users."
  echo   "You must redirect output back into /etc/group if you're satisfied"
  echo   "with the results."
  echo
  echo "Usage: $0 [ group ]"
  echo
  echo
  exit
fi

sed "s/:\(5[0-9]\{2\}\):/:\1:$1,/; s/,,/,/g; s/,$//g" /etc/group.new
Sorry I'm not going to do everything for you.

Use the 'groupadd' command to add the group you want. Type 'man groupadd' to figure out how to use it.

To add that new group to all 'normal users', run '<script> NewGroup'. If you like the output, make a backup copy of /etc/group and copy /etc/group.new over /etc/group.

Feel free to ask me about the regular expression used to find the normal users in the group file (if you're interested) and I'll try and explain.
 
  


Reply



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
helping in cgi script that add users to the system adam_blackice Programming 14 04-16-2007 02:41 AM
howto add users to group? Lleb_KCir Linux - General 2 06-04-2005 12:28 AM
"adduser" not adding users to default group "users" PunkPT Slackware 2 09-23-2004 11:50 AM
add all users as audio group Kocil Linux - Security 1 07-27-2004 02:28 AM
add users to new group, non-GUI jules_fraser Linux - Newbie 3 01-22-2004 06:37 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Server

All times are GMT -5. The time now is 06:06 PM.

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