expect 执行ssh-copy-id

Posted mulinux

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了expect 执行ssh-copy-id相关的知识,希望对你有一定的参考价值。

vi deploy_ssh_key.exp

#!/usr/bin/expect -f

set timeout 2
set ipaddress [lindex $argv 0]
set passwd "[email protected]"

spawn ssh-copy-id "-p2222 [email protected]$ipaddress"

expect {
"yes/no" { send "yes\r";exp_continue }
"password:" { send "$passwd\r" }
}
expect "#"

 

for x in `cat ip.txt | awk ‘{print $1}‘`;do ./deploy_ssh_key.exp $x;done

以上是关于expect 执行ssh-copy-id的主要内容,如果未能解决你的问题,请参考以下文章