Home Forums OS X Server and Client Discussion Questions and Answers Adding "Mail" to all users in NetInfo/LDAP databas

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #355389
    Anonymous
    Participant

    Hi folks,

    How can I write a script (sh or whatever) to…

    1) check each user in our NetInfo listing for existance of a “mail” tag

    2) If it doesn’t exist, add a “mail” tag to that user and populate with their e-mail address ([email protected])

    I want to set this up as a cron job to run once each week to account for any new users, etc.

    I know how to do this manually using netInfo manager, just don’t want to do this for all 1000+ users in our database.

    cheers,

    Kent Lendrum
    HOD Computer Studies
    Mount Maunganui College
    New Zealand

    #355403
    Anonymous
    Participant

    For those who are interested, I’ve managed to write a .sh script which loops through each user in my NetInfo database and…

    1) Checks if a “Mail” tag already exists.
    2) if not, attempts to add one.

    This is working, however I needed to run it several times. Seems to have an error when attempting to add the tag “access denied”.
    If I run again, some users with the error are updated okay.
    I’ve managed to get to about 95% of my 1000+ users done.
    If I manually add the user, no problems. just in the script.

    still, I’ll live. better than on 5%

    cheers,

    Kent.

    #355411
    Cabbage
    Participant

    ….so post the script

    #355424
    Anonymous
    Participant

    Sorry, was at home when I posted my reply. I’ve included the script below. Any feedback on why only works for some users would be greatly appreciated.

    cheers,

    Kent.
    —————————————————————————————————–
    #!bin/sh

    #Get all users in our NetInfo Database
    userList=`niutil -list / /users | cut -d” ” -f2`

    #loop through each user
    flag=
    for userName in ${userList}
    do

    # Check to see if “mail” entry already exists
    exists=`niutil -read / /users/$userName | grep “mail: $userName”`
    result=`expr “$exists” : ‘.*’`

    if (expr $result = 0)
    then
    # only create if doesn’t already exist
    niutil -createprop / /users/$userName mail ${userName}@mmc.school.nz
    echo “created $exists – $result”
    fi
    done

    exit 0

Viewing 4 posts - 1 through 4 (of 4 total)
  • You must be logged in to reply to this topic.

Comments are closed