30台机器,说多不多,说少不少.挨个人肉不是一个admin的行事风格..

放狗,翻书.试着写了几个脚本跑了一下,Log0里便划掉2个需求.

chmod/sudo

相关代码

#!/usr/bin/expect -f
#name : config_dns_ldap_via_ssh
#set variable
set username [lindex $argv 0]
set hostname [lindex $argv 1]
set password [lindex $argv 2]
set timeout -1
 
match_max 100000
# login
spawn ssh $username@$hostname
## get RSA BEGIN
# expect "*no)?*"
# send -- "yes\r"
## get RSA END
expect "*assword:*"
send -- "$password\r"
expect "*daroot$*"
send -- "sudo -K\r" # reset sudo password
expect "*$username$*"
## DNS name-server&search-domains config by ncutil BEGIN
send -- "sudo -S ncutil --apply-on-exit setprop /Automatic/AirPort/DNS name-server 192.168.1.100\r"
expect "*assword:*"
send -- "$password\r"
expect "*$username$*"
send -- "sudo ncutil --apply-on-exit setprop /Automatic/AirPort/DNS search-domains applestudio.da\r"
## DNS name-server&search-domains config by ncutil END
## add ldap server begin
expect "*$username$*"
send -- "sudo dsconfigldap -a 192.168.1.100\r"
## add ldap server end
## ldap search policy config begin
expect "*$username$*"
send -- "sudo dscl localhost -append /Search CSPSearchPath \"/LDAPv3/192.168.1.100\"\r"
expect "*$username$*"
send -- "sudo dscl localhost -create /Search SearchPolicy CSPSearchPath\r"
expect "*$username$*"
send -- "sudo dscl localhost -append /Contact CSPSearchPath \"/LDAPv3/192.168.1.100\"\r"
expect "*$username$*"
send -- "sudo dscl localhost -create /Contact SearchPolicy CSPSearchPath\r"
## ldap search policy config end
# logout
expect "*$username$*"
send -- "logout\r"
expect eof
#!/bin/bash
#name : loop
i=1
 
while [ $i -lt 31 ]
do
  if [ $i -gt 9 ]
    then $1 daroot imac$i [password]
    else $1 daroot imac0$i [password]
  fi
  i=`expr $i "+" 1`
done
 #loop是shell脚本的名字,config_dns_ldap_via_ssh是expect脚本的名字
$ loop config_dns_ldap_via_ssh

-
Expect脚本里sudo后面填的-S参数很重要,默认sudo是从console而不是stdin接受密码的输入.
脚本里ssh到远端后,远端执行的命令我都是用send模拟而不是spawn,暂时喜欢这样写,还不知道有什么弊端.

参考资料
www.google.com/ncr(不让Google自作聪明的跳转到谷歌中国)
Go2(配合对应FF扩展使用,翻墙效果更加)
-
Configure DNS lookups from the terminal
Using scutil to set DNS server
Terminal Syntax to add custom directory search path
Frey:/programming/ncutil
-
Schoun Regan, Mac OS X Server Essentials, Peachpit Press, 2005, ISBN: 9780321357588
Don Libes, A Tcl-based Toolkit for Automating Interactive Programs (Nutshell Handbook), O’Reilly Media, Inc., 1994, ISBN: 9781565920903
Arnold Robbins / Dale Dougherty, sed & awk (2nd Edition), O’Reilly Media, 1997, ISBN: 9781565922259
Paul Love / Joe Merlino / Craig Zimmerman / Jeremy C. Reed / Paul Weinstein, Beginning Unix, Wrox, 2005, ISBN: 9780764579943
(O’Reilly的电子书服务Safari Books Online真不错)

题外话,Thinkpad上的Hackintosh某次重启后不知怎的没声音了,又加之上星期武汉连续30度,发现Lenovo生产的TP散热上大不如前了,蓝屏数次后外购了Cooler Master 5218散热架,这玩意多少还管点用.顿时有了换MB(P)的强烈冲动..

Web前端开发上有一个好处就是可以相对轻松的查看和学习别人写的代码,现在的一大乐事就是用Firebug看那些pages.

机房-寝室/Mac-Win/.. : I hate the context-switch.

, , , , , , , , , , , , ,

你有什么想说的?

HOME | TOP
Powered by WordPress 2.7.1 | G7 v5M Theme produced by underone, modified by Dismory
Creative Commons 2.5 | Valid XHTML 1.0 and CSS 2.1