Home › Forums › OS X Server and Client Discussion › Questions and Answers › Adding "Mail" to all users in NetInfo/LDAP databas
- This topic has 3 replies, 2 voices, and was last updated 23 years, 7 months ago by
Anonymous.
-
AuthorPosts
-
March 26, 2003 at 11:10 pm #355389
Anonymous
ParticipantHi 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 (shortname@mmc.school.nz)
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 ZealandMarch 31, 2003 at 4:11 am #355403Anonymous
ParticipantFor 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.
March 31, 2003 at 5:14 pm #355411Cabbage
Participant….so post the script
April 1, 2003 at 10:25 pm #355424Anonymous
ParticipantSorry, 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
doneexit 0
-
AuthorPosts
- You must be logged in to reply to this topic.