Sponsored Content
Operating Systems OS X (Apple) bash script for dseditgroups in OSX Post 302487736 by stop.the.stupid on Thursday 13th of January 2011 11:36:45 PM
Old 01-14-2011
After reading around and talking to a friend who's done some bash scripting. I think I'm going to have to write a 'for' loop to define the variables after creating the group.

If/when I get this figured out I'll come back and share.

/stop

---------- Post updated at 09:36 PM ---------- Previous update was at 09:33 AM ----------

Well, here's what I've got. Probably way off but what do you think? Where have I gone wrong the most?
Code:
#!/bin/bash
#this is my attempt at writing a bash script which creates a non-admin group called 'cats'
#the script should add all users except the DOG and Shared users to the script
#this is my first attempt at writing a bash script and likely has errors
#don't run this script unless you know how to fix it first as it will likely cause your Mac to do odd things



# Change to the directory you want to use to parse though
cd /Users/

# Create a non-admin group using dseditgroup. Staff? what else would indicate it's to be a non-admin group?
# a group ID could be specified for more control

dseditgroup -o create cats -t staff
# not sure if this should have a -n included to indicate the node instead of using the default directory.

# This will loop though the directory specificed above and set each file and folder to variable a
for a in *;do
    # Looks to see if $a is a directory, if it is, then it continues, else it goes to done
    if [[ -d $a ]]; then
        # Excludes the Shared directory
        if [[ $a != "Shared" ]]; then
            # Excludes the dog directory
            if [[ $a != "dog" ]]; then
                # Excludes the DOG directory
                if [[ $a != "DOG" ]]; then
                    
                    dscl -u $a . -append /Groups/cats GroupMembership
                    # this is using dscl instead of dseditgroup to add all users indicated by the $a variable (excluding DOG and Shared above)
                    echo $a
                fi
            fi
        fi
    fi
done


dseditgroup -o checkmember . cats
#attempting to check the membership of the new group and have it print to verify it worked

echo $checkmember


exit

thanks for your feedback.

/stop

Last edited by Scott; 01-14-2011 at 04:16 AM.. Reason: Code taqs, please...
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Upgrading bash on Darwin (osx)

Hi, I have installed bash 3.2 via darwin ports, however when I try and change the shell i.e. chsh -s /opt/local/bin/bash is says its a non-standard shell? but if i run ./bash i get a new bash prompt with version 3.2? Thanks (3 Replies)
Discussion started by: c19h28O2
3 Replies

2. Shell Programming and Scripting

how to make your bash script run on a machine with csh and bash

hi, i have a script that runs on bash and would like to run it on a machine that has csh and bash. the default setting on that machine is csh. i dont want to change my code to run it with a csh shell. is there any way i can run the script (written in bash) on this machine? in other words is there... (3 Replies)
Discussion started by: npatwardhan
3 Replies

3. Shell Programming and Scripting

#!/bin/bash and #1bin/sh command not found error on mac osx terminal/shell script

i am having a weird error on mac os x running some shell scripts. i am a complete newbie at this and this question concerns 2 scripts. one of which a friend of mine wrote (videochecker.sh) a couple weeks ago and it's been running fine on another machine. then last week i wrote capture.sh and it... (2 Replies)
Discussion started by: danpaluska
2 Replies

4. UNIX for Dummies Questions & Answers

Mac OSX Cron Script Execution

Hello, On Mac OSX, I was wondering about my Cron Script: HELL=/bin/tcsh PATH=/sbin:/bin:/usr/sbin:/usr/bin HOME=/var/log MAILTO=jwillis 25 1 * * * root /Users/jwillis/Fbcmd\Scripts/DailyBirthday.scrmy returned message is: Subject: Cron... (3 Replies)
Discussion started by: jwillis0720
3 Replies

5. OS X (Apple)

Creating Shell Script for STIG Checklist MAC OSX 10.6

Hello, I am new to Mac OSX and shell scripting all together. I was wondering if anyone could help get me started in a few scenarios so that I would be able to automate checking a system against a STIG checklist. A STIG Checklist is a DoD Guideline for securing systems. Here is the first... (3 Replies)
Discussion started by: john3j04
3 Replies

6. Shell Programming and Scripting

open application with spaces in name [bash][OSX]

Hi guys, I'm new here and new to shell scripting so don't be hard on me I'm trying to create a bash script to restart a process by name in Mac OSX. I have no problem killing the application, the problem comes when launching it again. I managed to store the path in a variable lets say ... (8 Replies)
Discussion started by: jonathanwiesel
8 Replies

7. Shell Programming and Scripting

OSX, bash, cat with <<MARKER executing commands

I have a script that writes another script with cat >/usr/local/bin/myscript.sh <<EOF #!/bin/sh VAR=`run a command here` EOF Problem is, after this is run, I get: $ cat /usr/local/bin/myscript.sh #!/bin/sh VAR=result of command How do I stop that from happening with Macs... (2 Replies)
Discussion started by: jnojr
2 Replies

8. Shell Programming and Scripting

OSX bash & expect

I have a script that must perform a 'sudo' operation on each of a number of hosts. I'm trying to get expect working so I only have to enter it once, and have run into a couple of issues. First, several examples suggest to use: /usr/bin/expect <<EOD spawn ssh -t $host /usr/bin/sudo -v... (7 Replies)
Discussion started by: jnojr
7 Replies

9. Shell Programming and Scripting

How to block first bash script until second bash script script launches web server/site?

I'm new to utilities like socat and netcat and I'm not clear if they will do what I need. I have a "compileDeployStartWebServer.sh" script and a "StartBrowser.sh" script that are started by emacs/elisp at the same time in two different processes. I'm using Cygwin bash on Windows 10. My... (3 Replies)
Discussion started by: siegfried
3 Replies

10. UNIX for Beginners Questions & Answers

In Bash shell - the ps -ef shows only the /bin/bash but the script name is not displayed

In Bash shell - the ps -ef shows only the /bin/bash but the script name is not displayed ? Is there any way to get the script names for the process command ? --- Post updated at 08:39 AM --- in KSH (Korn Shell), my command output shows the script names but when run in the Bash Shell... (3 Replies)
Discussion started by: i4ismail
3 Replies
lgroupmod(1)						      General Commands Manual						      lgroupmod(1)

NAME
lgroupmod - Modify an user group SYNOPSIS
lgroupmod [OPTION]... group DESCRIPTION
Modifies the user group with name group. OPTIONS
-A, --admin-add=list Add users in comma-separated list among group's administrators. -a, --admin-remove=list Remove users in comma-separated list from group's administrators. Removing users that are not currently among group's administra- tors silently succeeds. -g, --gid=gid Change group's group ID to gid. -i, --interactive Ask all questions when connecting to the user database, even if default answers are set up in libuser configuration. -L, --lock Lock group. This prevents users from using the group password with newgrp(1) to become a member of group. -M, --member-add=list Add users in comma-separated list among group's members. -m, --member-remove=list Remove users in comma-separated list from group's members. Removing users that are not currently among group's members silently succeeds. -n, --name=name Rename group to name. -P, --plainpassword=password Set group's password to password. Note that the password can be viewed while running lgroupmod using tools such as ps(1). -p, --password=encrypted Set group's password to the password represented by the hash encrypted. Note that the hash can be viewed while running lgroupmod using tools such as ps(1). -U, --unlock Unlock group. EXIT STATUS
The exit status is 0 on success, nonzero on error. libuser Jan 11 2005 lgroupmod(1)
All times are GMT -4. The time now is 07:55 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy