interactive shell script to create users 10.4

Hello everyone,

Not sure if this is the right place, but OS X isn't your standard Unix, so I figured here would be best. I am looking at creating a script that will be interactive that admins can run to create users.

Now, 10.4 uses netinfo database and netinfo manager to handle it's users. So I am looking at writing a script using the niutil command that the admin can input the full name and the short name of the user and the script does the rest. When we migrate to 10.5 I'll have to convert this script over to the dscl command, but I will cross that bridge when I get there.

I am not quite sure how to make it interactive though, my scripting skills are intermediate at best.

Thanks,

Who will be running the interactive user add script? make the script executable by root and no one else. The person issuing the command (launching the script) will need "sudo" privileges, which all local admins accounts have by default.

Here is a page that will help you with the dscl commands:
Porting UNIX/Linux Applications to Mac OS X: Open Directory and the dscl Tool

10.4.x can use dscl too. Might as well use it if you aren't expecting to support the same function in 10.3.

You will basically poll the user for data, and store that data in a variable with the "read" command, for use in making decisions and issuing commands based on the users input.

Some interactive considerations:
echo "Enter a username: "
read username

echo "Add $username? (y/n):
read addflag

Test $addflag, then make the script check if the user already exists. and inform the user if so.

You can use the scripts variable $username where ever a username is required.

Don't take anything for granted. It is possible to add a username to the admin group multiple times, which, while it might not be catastrophic, is very messy. So test, test, test, deploy (but only if you feel it's been tested enough :wink: )

well this is for the very rare case of a non network managed machine which the users would set up local accounts and administer basically them self. However, they have requested an easy way to create and manage their own local user accounts so I was looking at making an interactive script. Which in return after that, I can make it sit on the local admin account's desktop and make an apple script to execute the shell script to make it double click executable. Then all they need to do is input the info in the open terminal screen and exit when finished.

There will be one person with admin rights and the rest of the accounts will be managed.

I have written plenty of simple shell scripts in my time but never one fully interactive, other than a menu based shell script that just ran commands by inputting 1, 2, 3, 4 etc, and 0 to exit. I have never written anything that actually asked for input, and then took that input and inserted it into a script.

For creating a regular user account from the command line interactively, try: Create & delete user accounts from the command line on Mac OS X

Cheers,
verno