expect+TCL實現批量機器SSH免登錄
分享一段expect+TCL自動化代碼,作用是在在任何一台Linux機器執行對其他Linux節點的免密碼登錄SSH:#!/usr/bin/expect
set ip
set passwd
spawn scp /root/.ssh/authorized_keys root@$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!