openldap 批量增加或修改属性

1. 把excel表导入数据库再编程生成或直接生成需要修改的ldif格式文件,命名为modify.ldif

文件内容格式如下:

dn: uid=20180103,ou=201801,ou=2018,ou=student,ou=people,dc=linbsoft,dc=com
changetype: modify
add: mobile
mobile: 13812345678
【空行】
dn: uid=20180104,ou=201801,ou=2018,ou=student,ou=people,dc=linbsoft,dc=com
changetype: modify
replace: mobile
mobile: 13912345678
【空行】
.....

其中 add是增加属性,replace是修改已存在属性

2. 把文件上载到linux服务器

3.运行bash命令

#ldapmodify -x -D "cn=admin,dc=linbsoft,dc=com" -W -f modify.ldif

该命令会提示输入openldap管理员账号admin的密码,然后执行修改openldap属性的操作,注意如果其中某个属性修改出错,会中断执行,造成部分后面的修改操作没有完成。

4.如果导入照片,可以使用如下语法

jpegPhoto: < file:///stuphoto/2018/201801/20180103.jpg

5.以下是把excel导入到mssql后,vb.net生成ldif的程序

        Protected Sub Button1_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Button1.Click
            Dim mydbObject As DBObject = New DBObject
            Dim bh As String = TextBox1.Text.Trim
            Dim nj As String = Left(bh, 4)

            Dim sqlstr As String = "select xh,mobile  from mobile" + nj + " where bj='" + bh + "'"
            Dim set1 As DataSet = mydbObject.ExecuteSql(sqlstr, "t1")
            Dim drow As DataRow
            Dim xh As String
            Dim mobile As String
            TextBox2.Text = ""
            TextBox2.Text += Chr(10)
            For Each drow In set1.Tables(0).Rows
                xh = drow("xh").ToString.Trim
                mobile = drow("mobile").ToString.Trim
                If mobile.Length > 7 Then
                    TextBox2.Text += Chr(10)
                    TextBox2.Text += "dn: uid=" + xh + ",ou=" + bh + ",ou=" + nj + ",ou=student,ou=people,dc=linbsoft,dc=com" + Chr(10)
                    TextBox2.Text += "changetype: modify" + Chr(10)
                    TextBox2.Text += "add: mobile" + Chr(10)
                    TextBox2.Text += "mobile: " + mobile + Chr(10)
                End If
            Next
        End Sub

猜你喜欢

转载自blog.csdn.net/oLinBSoft/article/details/83379162