# Mac OS X: 实用脚本程序(bash scripts)系列-8
# AD Binding的一个脚本实例
Active Directory在现实企业管理中已经成为了现实的标准,Open Directory, Active Directory,或者eDirectory等都是基于Directory原理实现的,都有各自的实现和扩展,各有优势。基于现实中PC机和AD服务在企业中应用的普及性,在企业中把Mac或者其它系统纳入AD管理,也就是AD集成可以说在企业中的应用很普遍。实际中要考虑系统版本号的兼容,自己企业AD的配置情况,管理特点,当然别忘了把客户计算机先加入到AD中,设置相应的GPO和管理环境所需的管理组等。
下面的脚本就是一个实际企业环境中把Mac系统纳入到AD管理环境的实际例子. 谨和大家分享:
<table id="x_6f" border="1" cellspacing="0" cellpadding="3" width="100%" bordercolor="#000000"><tbody><tr><td width="100%"><p> #--------------------------------------------------------------------------------------<br/> # Check for Valid Corp Network IP Address<br/> CorpIP=""<br/> check=20<br/>Limit=check<br/> X=0<br/> while [ "$CorpIP" = "" ]<br/> do<br/> echo "Checking valid IP detected...$check times."<br/> CorpIP=$(ifconfig| grep "inet 10.")<br/> X=$((X+1))<br/> if [ $X -ge $limit ]; then<br/> CorpIP="NO_ValidIP"<br/> break<br/> fi<br/> check=$((check-1))<br/> sleep 2<br/> done<br/><br/> echo "Detected IP: $CorpIP"<br/><br/> if [ "$CorpIP" = "NO_ValidIP" ]; then<br/> echo "Binding failed! Valid Corp Network not detected!"<br/> osascript -e 'set volume 4'<br/> say "Binding failed! Valid Corp IP Address not detected!"<br/> exit 1<br/> fi<br/><br/>#--------------------------------------------------------------------------------------<br/> # Host-specific parameters<br/> #--------------------------------------------------------------------------------------<br/> computerid=`/usr/sbin/scutil --get LocalHostName`<br/><br/> #--------------------------------------------------------------------------------------<br/> # Standard Parameters used to Bind Workstation to AD<br/> #--------------------------------------------------------------------------------------<br/> domain="Corp.com"<br/> udn="MacADIAdmin"<br/> password="Mac1nt0SH"<br/> ou="CN=Computers,DC=Corp,DC=com"<br/><br/> #--------------------------------------------------------------------------------------<br/> # Advanced Options for AD Plugin<br/> #--------------------------------------------------------------------------------------<br/> alldomains="enable" <br/> localhome="disable"<br/> protocol="afp" <br/> mobile="disable" <br/>mobileconfirm="disable" <br/>useuncpath="enable"<br/> user_shell="/bin/bash"<br/>preferred="-nopreferred"<br/>admingroups="Corp/WSAdmins"<br/> searchPathLDAP=`cat/Library/Preferences/DirectoryService/SearchNodeConfig.plist | grepLDAPv3 | sed -e 's!string>!!g' -e 's!<//!!g' | tr -d '/t'`<br/><br/> #--------------------------------------------------------------------------------------<br/> # Synchronize Time with Corp Network Time Server<br/> #--------------------------------------------------------------------------------------<br/> echo "Setting the Network Time Server to 10.0.1.1 ... Please Wait"<br/> "$1/Contents/Resources/systemsetup-tiger" -setusingnetworktime off >& /dev/null<br/> "$1/Contents/Resources/systemsetup-tiger" -setnetworktimeserver 10.0.1.1 >& /dev/null<br/> "$1/Contents/Resources/systemsetup-tiger" -setusingnetworktime on >& /dev/null<br/><br/> echo "Restarting Network Time Service... Please Wait"<br/> SystemStarter -d restart "Network Time" >& /dev/null<br/><br/> #--------------------------------------------------------------------------------------<br/> # Attempt to force unbind the workstation<br/> #--------------------------------------------------------------------------------------<br/> echo "Attempting a force unbind in case system is already bound to AD... Please Wait."<br/> dsconfigad -r -f -u baduser -p badpass >& /dev/null<br/><br/> #--------------------------------------------------------------------------------------<br/> # Disable Unused Protocols<br/> #--------------------------------------------------------------------------------------<br/> echo "Disable all unused protocols (AppleTalk, BSD, SMB, SLP)... Please Wait."<br/> defaults write /Library/Preferences/DirectoryService/DirectoryService AppleTalk -string Inactive<br/> defaults write /Library/Preferences/DirectoryService/DirectoryService BSD -string Inactive<br/> defaults write /Library/Preferences/DirectoryService/DirectoryService SMB -string Inactive<br/> defaults write /Library/Preferences/DirectoryService/DirectoryService SLP -string Inactive<br/> plutil -convert xml1 /Library/Preferences/DirectoryService/DirectoryService.plist<br/><br/> #--------------------------------------------------------------------------------------<br/> # Activate the AD plugin<br/> #--------------------------------------------------------------------------------------<br/> echo "Activating AD Plugin... Please Wait."<br/> defaults write /Library/Preferences/DirectoryService/DirectoryService "Active Directory" "Active"<br/> plutil -convert xml1 /Library/Preferences/DirectoryService/DirectoryService.plist<br/><br/> #--------------------------------------------------------------------------------------<br/> # Bind to AD<br/> #--------------------------------------------------------------------------------------<br/> echo "Binding system to AD as '$computerid'... Please Wait."<br/> bind_result=`dsconfigad -f -a $computerid -domain $domain -u $udn -p "$password" -ou "$ou"`<br/><br/> if [ "$bind_result" != "Computer was successfully Added to Active Directory." ]; then<br/> echo "Binding failed! Check the Computer Name and ensure it has an account in Active Directory"<br/> osascript -e 'set volume 4'<br/> osascript -e 'say "I am sorry but Active Directory binding failed!Please check the computer name and ensure this system has an account inActive Directory." using "Vicki"'<br/> exit 1<br/> else<br/> echo "$bind_result"<br/> fi</p><p> </p><p># Write value so workstation can be easily identified being bound to AD<br/> defaults write /Library/Preferences/com.apple.RemoteDesktop "Text4" 'Bound to AD - OSXServer - v2.0'<br/><br/> #--------------------------------------------------------------------------------------<br/> # Configure advanced AD plugin options<br/> #--------------------------------------------------------------------------------------<br/> echo "Configuring Advanced AD Plugins... Please Wait."<br/> if [ "$admingroups" = "" ]; then<br/> dsconfigad -nogroups<br/> else<br/> dsconfigad -groups "$admingroups"<br/> fi<br/><br/> dsconfigad -alldomains $alldomains -localhome $localhome -protocol $protocol /<br/> -mobile $mobile -mobileconfirm $mobileconfirm -useuncpath $useuncpath /<br/> -shell $user_shell $preferred<br/><br/> #--------------------------------------------------------------------------------------<br/> # Add the AD node to the search path<br/> # Delay a bit to give the Directory Service a chance to catch its breath<br/> #--------------------------------------------------------------------------------------<br/> echo "Adding AD to Search Path... Please Wait."<br/><br/>if [ "$searchPathLDAP" = "" ] || [ `echo $searchPathLDAP| grep127.0.0.1` ] || [ `echo $searchPathLDAP| grep localhost` ]; then<br/> echo "No existing LDAP path... Only writing AD. Please Wait."<br/> defaults write/Library/Preferences/DirectoryService/SearchNodeConfig "Search NodeCustom Path Array" -array "/Active Directory/All Domains"<br/> defaults write /Library/Preferences/DirectoryService/SearchNodeConfig "Search Policy" -int 3<br/> plutil -convert xml1 /Library/Preferences/DirectoryService/SearchNodeConfig.plist<br/><br/>else<br/> echo "LDAP path is /$searchPathLDAP... Writing AD as first search and LDAP second. Please Wait."<br/> defaults write/Library/Preferences/DirectoryService/SearchNodeConfig "Search NodeCustom Path Array" -array "/Active Directory/All Domains""/$searchPathLDAP"<br/> defaults write /Library/Preferences/DirectoryService/SearchNodeConfig "Search Policy" -int 3<br/> plutil -convert xml1 /Library/Preferences/DirectoryService/SearchNodeConfig.plist<br/> fi<br/><br/> #--------------------------------------------------------------------------------------<br/> # Restart DirectoryService (necessary to reload AD plugin activation settings)<br/> #--------------------------------------------------------------------------------------<br/> echo "Restarting DirectoryService... Please Wait."<br/> sleep 2<br/> killall DirectoryService >& /dev/null<br/> sleep 8<br/><br/> #--------------------------------------------------------------------------------------<br/> # Disable autologin - If it's enabled<br/> #--------------------------------------------------------------------------------------<br/> echo "Disabling autologin if enabled... Please Wait."<br/> defaults delete /Library/Preferences/com.apple.loginwindow autoLoginUser >& /dev/null<br/> srm /etc/kcpassword >& /dev/null<br/><br/> #--------------------------------------------------------------------------------------<br/> # Complete<br/> #--------------------------------------------------------------------------------------<br/> echo "Done. AD Bind Successful."<br/> exit 0 </p></td> </tr></tbody></table>
- 前言
- Mac OS X:如何将个人文件夹从默认卷移到其他卷(适合OSX10.5 Leopard)
- Mac OS X:Finder菜单中的Connect to Server选项禁止和打开
- Mac OS X: 苹果机支持的分区表类型及问题解决
- Mac OS X: 偏好Preferences基础(1)
- Mac OS X: 如何变更Office for Mac的注册码
- Mac OS X: 禁止/防止网络用户复制app程序到桌面
- Mac OS X: 用户帐户的选择
- Mac OS X: 实用脚本程序(bash scripts)系列
- Mac OS X: 共享iPhoto图片
- Mac OS X: 实用脚本程序(bash scripts)系列-2
- Mac OS X: 实用脚本程序(bash scripts)系列-3
- Mac OS X: 实用脚本程序(bash scripts)系列-4
- Mac OS X: 实用脚本程序(bash scripts)系列-5
- Mac OS X: 实用脚本程序(bash scripts)系列-6
- Mac OS X:升级rsync和同步应用实例
- Mac OS X: XAMP在Mac上的实现
- Mac OS X瘦身多法
- Mac OS X 10.5快速系统部署实践-计划(2) v1
- Mac OS X 10.5快速系统部署实践-制作核心系统镜像(1) v1
- Mac OS X数据备份方案一例
- Mac OS X数据备份方案一例(2)
- Mac OS X 10.5快速系统部署实践-制作核心系统镜像(2) v1
- Mac OS X: 打印系统治疗
- Mac OS X:禁止崩溃报告
- Mac OS X:Snow Leopard的几个改动(管理员相关)
- Mac OS X排错:雪豹的最新更新Airport可能不支持无线802.11n网络
- Mac OS X:雪豹内置支持读写NTFS卷
- Mac OS X:定制生成新用户的程序包
- Mac OS X:在Windows里面使用命令行设置启动系统
- Mac OS X: 实用脚本程序(bash scripts)系列-7
- Mac OS X:一种从APP中获得PKG的方法
- Mac OS X: bash脚本实现添加无线SSID(Update2009-10-09)
- Mac OS X: 实用脚本程序(bash scripts)系列-8
- Mac OS X 10.5快速系统部署实践-制作核心系统镜像(4) v1
- Mac OS X: 彻底删除GeekTool(bash脚本)
- Mac OS X: 实用脚本程序(bash scripts)系列-9
- 把你的Leopard变成Mac OS X的系统发布服务器(1)
- 把你的Leopard变成Mac OS X的系统发布服务器(2)
- 把你的Leopard变成Mac OS X的系统发布服务器(3)
- Mac OS X: 访问控制远程CUPS服务
- Mac &amp; Win混合平台访问和工具
- Mac OS X: DeployStudio更新v1.0rc16
- Mac: 想当Apple菜鸟不容易(1)
- Mac: 想当 Apple菜鸟不容易(2)
- Mac: 想当 Apple菜鸟不容易(3)
- Mac: 想当 Apple菜鸟不容易(4完)
- Mac电脑上处理摄像机上的存储内容
- Mac OS X: Google自动更新程序的卸载
- 雪豹系统和SMB不兼容的问题的解决汇总
- Mac OS X: 实用脚本程序(bash scripts)系列-10
- Mac OS X:MagicPrefs介绍
- Mac OS X: 系统部署后程序安装的用户提示
- Mac OS X:开启单程序模式
- Mac OS X: 在脚本里关闭Airport
- Mac笔记本电池:十点建议和其它
- Mac OS X: Launchd执行程序的一个例子
- Mac OS X:修改SMART Utility期限限制
- Mac OS X:网络用户环境个性配置实例
- Mac OS X:强制退出CD/DVD盘
- Mac OS X: launchd plist在线编辑器
- Mac OS X: 实用脚本程序(bash scripts)系列-11
- Mac OS X: 实用脚本程序(bash scripts)系列-12
- Mac: 卸载Safari 5.0.2
- Mac OS X: 实用脚本程序(bash scripts)系列-13
- Mac OS X: 文件图标制作和变更(Resource Fork)
- Mac OS X 10.6.6更新之后NTFS只读的解决
- Mac: 网络用户遇到Adobe Reader 9.x/10.x异常退出的解决
- Mac OS X: airport命令的参数
- Mac OS X的Spotlight综述
- Mac OS X:AFP和SMB共享配置详细配置
- Mac OS X:详细解读Munki和应用
- Mac OS X:显示/设置分辨率的命令(源程序)
- Mac OS X: 是否升级到Lion?
- OSX: 禁止Flash Player 10.3自动更新
- OSX脚本:禁止系统自动添加AppStore图标到用户Dock上
- 狮子GM版本的安装
- OS X Lion狮子安装盘的初步研究
- OS X Lion狮子的恢复盘的删除二法
- OSX: Finder的侧边栏(Sidebar)不显示已装载的网络共享
- OSX:隐藏文件或文件夹
- OS X: 实用脚本程序(bash scripts)系列-13
- OS X: 实用脚本程序(bash scripts)系列-14
- OSX:Lion支持登录窗口的Policy Banner
- OSX: 让狮子说中文