#!/bin/sh # # vim:sw=2 ts=8:et sta:fdm=marker # # # Copyright (c) 2008 Ariff Abdullah # All rights reserved. # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions # are met: # 1. Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # 2. Redistributions in binary form must reproduce the above copyright # notice, this list of conditions and the following disclaimer in the # documentation and/or other materials provided with the distribution. # # THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE # ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF # SUCH DAMAGE. # # $MyBSD$ # # Date: Wed Sep 17 00:34:19 MYT 2008 # OS: FreeBSD miki.MyBSD.org.my 8.0-CURRENT i386 # master="my_group.csv" user="my_user.csv" tempfile1="/tmp/1_${master}.$$.$$.CRAP" tempfile2="/tmp/2_${master}.$$.$$.CRAP" trap "rm -f $tempfile1 $tempfile2" 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 oifs="$IFS" export IFS="," cat $master > $tempfile1 col -b < $user | while read x1 x2 x3 x4 x5 x6 x7 x8 x9 x10 ; do if [ -z $x10 ]; then mailaddr=$x9 else mailaddr=$x10 fi case "$x1" in \"CN=*) #echo "'$x1' -> '$mailaddr'" sed -e "s/${x1}[^\"]*\"/${mailaddr}/" < $tempfile1 > $tempfile2 mv -f $tempfile2 $tempfile1 ;; *) ;; esac done export IFS="$oifs" cat $tempfile1 rm -f $tempfile1 $tempfile2