DirectNET

Data Center Management Solutions including UPS Systems, Data Center Cooling, KVM over IP & IP Power Strips, Server Racks and Server Rack accessories; KVM Switches and KVM Extenders; Rackmount Monitors and Rackmount Keyboards.


NAVIGATION
Home
Store
INSIDE MAC
Television Shows
Broadcast Shows
Daily News Shows
Special Shows
EVENTS
DAILY TIPS
Design
Mac OS X
Mac OS X UNIX
COMMUNITY
Forums
Surveys
NEWS
Current
Press
Archive
FEATURES
Editorial
Dr. Mac
Reviews
Reader Reports
RESOURCES
FAQ
Documentation
Learning Center
MAN pages
Glossary
Tutorials
Tips
Links

OUR PARTNERS

OSXFAQ Mac OS X UNIX Tip-of-the-Day   back to index

Week 91 - User Accounts (6 December 2004)

by Adrian Mayo - Editor, OSXFAQ

Thursday - Add a New Group

This script adds a new group to OS X. Give the group name and id. The group will be created without any users belonging to it. Add users to the group with add-user2group (see Friday).

Lots of checks are made, as you can see from the script comments.

Grab the script from here.

NOTE: THIS SCRIPT IS WRITTEN FOR PANTHER (10.3)

#!/bin/bash

# Create a group. # Takes a group name and gid and creates a new group in NetInfo groups
usage () { echo "Create a new group" echo "Usage: ${0##*/} groupname gid" if [ "$*" != "" ]; then echo " Error: $*"; fi exit 1 }

# The script must be run as root # if [ "$USER" != "root" ]; then echo "Must be run as root." exit 1 fi

# Check parameters # if [ $# -ne 2 ]; then usage fi
group=$1; gid=$2
# search NetInfo for the given group - it should not exist str="$(nireport . /groups name | grep -w $group)" if [ ! -z "$str" ]; then usage "Group $group already exists" fi
# search NetInfo for the given gid - it should not exist str="$(nireport . /groups gid | grep -w $gid)" if [ ! -z "$str" ]; then usage "Group ID $gid already exists" fi

# Add the new group to NetInfo # # add group and essential properties dscl . create /groups/$group dscl . create /groups/$group name $group dscl . create /groups/$group passwd "*" dscl . create /groups/$group gid $gid #dscl . create /groups/$group users "" breaks add-user2group if added as a blank value
echo "New group $group created" echo "Now add users to it with add-user2group"
exit 0

Discuss this trick in the Learning Center forum


If you want to learn more about Mac OS X Unix visit the Learning Center  click.

  • For beginners: Mac OS X Unix Tutorials
  • For detailed information on specific topics: Advanced Unix
  • For OS X in gereral: Mac OS X Tutorials

Copyright © 2000-2009 Inside Mac Media, Inc. All rights reserved.
Apple assumes no responsibility with regard to the selection, performance, or use of the products or services. All understandings, agreements, or warranties, if any, take place directly between the vendors and prospective users.
Apple, the Apple logo, Mac, PowerMac G4, PowerMac G5, Xserve, Xserve RAID, PowerBook, iBook, Airport, AirPort Extreme, iMac, eMac, iLife, iMovie, iCal, iPhoto, iTunes, QuickTime, FireWire, iPod, iSight, AppleWorks, Macintosh, Jaguar, Panther, Mac OS, Mac OS X and Mac OS X Server are trademarks of Apple Computer, Inc.