首页 > 其他 > 详细

使用expect 批量分发ssh公钥

时间:2017-05-26 21:31:36      阅读:240      评论:0      收藏:0      [点我收藏+]
#!/usr/bin/expect
if {$argc != 2} {  #首先注意大话号,彼此之间需要空格
  send_user "USAGE:expect_sshkey.exp file host"
  exit
}

#define var
set file [lindex $argv 0]
set host [lindex $argv 1]
set password "12345"

#spawn
spawn ssh-copy-id -i $file "-p52113 jpinsz@$host" >/dev/null 2>&1

#expect
expect { #也是要注意大话号,与首单词之间需要空格
        "yes/no" {send "yes\r";exp_continue}
        "*password" {send "$password\r";send_user "eof/n"}
}

expect eof

根据这个脚本,当目标主机已经存在sshkey时,将不会提示“yes/no”、“*password”,因此也不会有eof,所以会有
spawn id exp4 not open这个报错!!


使用expect 批量分发ssh公钥

原文:http://jpinsz.blog.51cto.com/12945987/1929872

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!