虚拟机练习用expect批量分发ssh公钥出现的:

  • #!/usr/bin/expect
  • if { $argc != 2 } {
  • send_user "Usage:expect usage.exp UserName IPdress\n"
  • exit
  • }
  • - set username [lindex $argv 0]
  • set ip [lindex $argv 1]
  • set password "123456"
  • - spawn ssh-copy-id -i ~/.ssh/id_dsa.pub $username@$ip
  • - set timeout 10
  • expect {
  • "yes/no" {send "yes\r";exp_continue}
  • "*password" {send "$password\r"}
  • }
  • expect eof
  • exit
  • 复制代码

#执行后提示如下错误
#[root@NFS_Server scripts]# expect usage_sshkey.exp root 192.168.253.138
#spawn ssh-copy-id -i ~/.ssh/id_dsa.pub [root@192.168.253.138](mailto:root@192.168.253.138)
#/usr/bin/ssh-copy-id: ERROR: No identities found
#expect: spawn id exp4 not open

while executing

#"expect eof"

(file "usage_sshkey.exp" line 18)