Bash
1 前言
一个问题,一篇文章,一出故事。
笔者最近写一个Shell发现同一个脚本需要引用两个以上AD域服务器连接,于是想着根据“域名”关键字动态获取不同的两台服务器连接参数。
2 最佳实践
declare -A ldap ldap['cmdschool.org.Host']='cmdschool.org' ldap['cmdschool.org.Port']='389' ldap['cmdschool.org.BindDN']='CN=admin,CN=Users,DC=cmdschool,DC=org' ldap['cmdschool.org.Passwd']='adminPasswd' ldap['cmdschool.org.BaseDN']='DC=cmdschool,DC=org' ldap['cmdschool.com.Host']='cmdschool.com' ldap['cmdschool.com.Port']='3268' ldap['cmdschool.com.BindDN']='CN=admin,CN=Users,DC=cmdschool,DC=com' ldap['cmdschool.com.Passwd']='adminPasswd' ldap['cmdschool.com.BaseDN']='DC=cmdschool,DC=com' domain="cmdschool.org" echo "${ldap[$domain.Host]}" echo "${ldap[$domain.Port]}" echo "${ldap[$domain.BindDN]}" echo "${ldap[$domain.Passwd]}" echo "${ldap[$domain.BaseDN]}"
没有评论