expect+TCL实现批量机器SSH免登录
分享一段expect+TCL自动化代码,作用是在在任何一台Linux机器执行对其他Linux节点的免密码登录SSH:#!/usr/bin/expectset ip
set passwd
spawn scp /root/.ssh/authorized_keysroot@$ip:/root/.ssh/authorized_key1
set i 1
while {$i<3} {
expect {
"password" {send "$passwd\n";set i 4}
"yes" {send "yes\n"}
}
}
expect eof
spawn ssh root@10.1.1.1
set j 1
while {$j<3} {
expect {
"password" {send "abc123\n";set j 4}
"yes"{send "yes\n"}
"]#" {send "exit\n"; set j 4}
}
}
expect "#"
send "hostname\n"
expect "#"
send "cat /root/.ssh/authorized_key1 >> /root/.ssh/authorized_keys\r"
expect "#"
send "exit\n"
expect eof 呵呵,分享一下。 感谢分享
http://blog.chinaunix.net/uid-11121450-id-322213.html thanks for you information!!!have a nice day!
页:
[1]