my2005lb 发表于 2013-09-25 09:29

expect+TCL实现批量机器SSH免登录

分享一段expect+TCL自动化代码,作用是在在任何一台Linux机器执行对其他Linux节点的免密码登录SSH:#!/usr/bin/expect
set 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

my2005lb 发表于 2013-09-25 09:30

呵呵,分享一下。

Shell_HAT 发表于 2013-09-25 10:21

感谢分享
http://blog.chinaunix.net/uid-11121450-id-322213.html

wenhq 发表于 2013-09-28 14:00

thanks for you information!!!have a nice day!
页: [1]
查看完整版本: expect+TCL实现批量机器SSH免登录