shell中使用expect批量ssh-copy-id

#!/bin/bash

password=Jdyun@2019

for i in {1..3}
  do
    expect <<-EOF
    set timeout 5
    spawn ssh-copy-id -i root@jdc$i
    expect {
    "yes/no" { send "yes\n";exp_continue }
    "password:" { send "$password\n" }
    }
  interact
  expect eof
EOF
done

 

 

EOF行前后不能有空格

posted @ 2019-05-22 14:52  guoxin0126  阅读(527)  评论(0编辑  收藏  举报