BASH指令碼 OpenLDAP匯入AD組織結構

2022-09-06 10:45:24 字數 2444 閱讀 6093

#!/bin/bash

# 預定義引數

ad_domain=""

ad_admin_dn="cn=,ou=***,ou=***,dc=***,dc=***,dc=***"

ad_admin_pwd=""

ad_base_dn="dc=***,dc=***,dc=***"

ldap_domain=""

ldap_admin_dn="cn=manager,dc=***,dc=***,dc=***"

ldap_admin_pwd=""

# 先從ad上獲取ou組織資訊,並儲存成ldif檔案

/usr/bin/ldapsearch -x -h ldaps://$:636 "(&(objectclass=top)(objectclass=organizationalunit))" dn objectclass ou -d "$" -w "$" -b "$" -l > /root/openldapshell/tmp_ldapgroup.ldif

# 匯入ad的組織結構

/usr/bin/ldapadd -x -c -w "$" -d "$" -f /root/openldapshell/tmp_ldapgroup.ldif > /dev/null 2>&1

# 把所有的ou都查出來,為一會匯入使用者做準備,因為現在ad的人數太多了,所以只能按ou分別匯入/更新

/usr/bin/ldapsearch -x -h ldaps://$:636 "(&(objectclass=top)(objectclass=organizationalunit))" dn -d "$" -w "$" -b "$" -l |php /root/openldapshell/utf8ldif.php > /root/openldapshell/tmp_ldapgroup_utf8.ldif

# 整理一下ldap ou的檔案,把version,注釋之類的都去掉,只留ou的dn資訊

/usr/bin/sed -i "/^#/d" /root/openldapshell/tmp_ldapgroup_utf8.ldif

/usr/bin/sed -i "/^version/d" /root/openldapshell/tmp_ldapgroup_utf8.ldif

/usr/bin/sed -i "/^[[:space:]]*$/d" /root/openldapshell/tmp_ldapgroup_utf8.ldif

/usr/bin/sed -i "s/^dn: //g" /root/openldapshell/tmp_ldapgroup_utf8.ldif

# 開始迴圈讀取ou,一行就是乙個ou

while read line

do# 獲取這個ou下的所有使用者,並儲存成ldif檔案

/usr/bin/ldapsearch -x -h ldaps://$:636 "(&(objectclass=organizationalperson)(!(objectclass=computer)))" dn objectclass cn description samaccountname usncreated -d "$" -w "$" -b "$" -l > /root/openldapshell/tmp_ldapuser.ldif

# 整理一下ldif的檔案,使其適應openldap的匯入格式

/usr/bin/sed -i "/^samaccountname: /h;s/^samaccountname: /userpassword: /;x" /root/openldapshell/tmp_ldapuser.ldif

/usr/bin/sed -i "/^objectclass: user/d" /root/openldapshell/tmp_ldapuser.ldif

/usr/bin/sed -i "/^cn:/h;s/^cn:/sn:/;x" /root/openldapshell/tmp_ldapuser.ldif

/usr/bin/sed -i "s/^samaccountname:/uid:/g" /root/openldapshell/tmp_ldapuser.ldif

/usr/bin/sed -i "/^objectclass: organizationalperson/h;s/^objectclass: organizationalperson/objectclass: inetorgperson/;x" /root/openldapshell/tmp_ldapuser.ldif

/usr/bin/sed -i "s/^usncreated:/employeenumber:/g" /root/openldapshell/tmp_ldapuser.ldif

# 匯入使用者

/usr/bin/ldapadd -c -x -w "$" -d "$" -f /root/openldapshell/tmp_ldapuser.ldif > /dev/null 2>&1

done

oralce導指令碼

用命令匯出 dmp c users administrator exp cms cms 10.196.149.11 orcl owner cms file d dmp 1 將資料庫sampledb完全匯出,使用者名稱system 密碼manager 匯出到e sampledb.dmp中 exp sy...

bash 指令碼筆記

輸入了什麼引數 輸入了多少個引數 1輸入的第乙個引數,依此類推,直到 9 上一次的執行結果 為 1 2 3 一起被引號包住 為 1 2 3 分別被包住 為3 引數數量 d target target 是否是 目錄 f target 是否是檔案 e target 是否存在 目錄和檔案都適用 x tar...

bash指令碼基礎

shell 指令碼 一 如何建立新shell指令碼?1.建立包含bash命令的文字檔案。檔案第一行應為 bin bash 2.使檔案可執行 使用chmod x scripts 3.將檔案放置在使用者的 path的目錄中 bin 用於使用者的私有程式 usr local bin 本地開發 系統上的其他...