LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
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, 12:23 PM   #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, 04: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, 07: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, 07: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, 02: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, 05: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


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


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

Main Menu
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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration