Created
May 15, 2014 03:26
-
-
Save machuz/49c09a1a833fc835d5e7 to your computer and use it in GitHub Desktop.
LDAP登録スクリプト
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
cn="" | |
dn="" | |
ou="" | |
ldap_password="" | |
# 一番大きいuidを取得 | |
last_uidnumber=`ldapsearch -x -D cn=$cn -h localhost -w$ldap_password -b ou=$ou | grep uidNumber |awk '{if(m<$2) m=$2} END{print m}'` | |
numLine=1 | |
cat $1 | while read line | |
do | |
uid=`expr $last_uidnumber + $numLine` | |
role=`echo $line | awk '{print $1}'` | |
id=`echo $line | awk '{print $2}'` | |
mail=`echo $line | awk '{print $3}'` | |
lastname=`echo $mail | sed -e "s/^\(.*\)_\(.*\)@.*$/\1/"` | |
firstname=`echo $mail | sed -e "s/^\(.*\)_\(.*\)@.*$/\2/"` | |
password=`echo $line | awk '{print $4}'` | |
password=`slappasswd -h '{SSHA}' -s $password` | |
shell="/usr/sbin/nologin" | |
case "$role" in | |
"player") gid="10005";; | |
"manager") gid="10004";; | |
"engineer") gid="10001" | |
shell="/bin/bash";; | |
esac | |
filename="$role/$id.ldif" | |
cat << EOF > $filename | |
dn: uid=$id,$dn | |
objectClass: inetOrgPerson | |
objectClass: posixAccount | |
objectClass: shadowAccount | |
objectClass: ldapPublicKey | |
sn: $lastname | |
cn: $firstname | |
uid: $id | |
uidNumber: $uid | |
gidNumber: $gid | |
homeDirectory: /home/$id | |
userPassword: $password | |
mail: $mail | |
loginShell: $shell | |
EOF | |
numLine=$((numLine + 1)) # 行数を1増やす | |
/usr/bin/ldapadd -x -D cn=$cn -w$ldap_password -H ldapi:// -f $filename | |
sleep 1 | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment