复制密钥到目标机器

徘徊边缘 提交于 2019-12-03 12:05:08
##1.shell脚本
#!/bin/sh

BASE_DIR=`dirname $0` && cd $BASE_DIR

function ssh_copy_id(){
  for ip in `cat .ips-other`;do
    expect auto-ssh-copy-id.exp $ip container `cat .password`
    if [ $? -ne 0 ]; then
      echo "免认证失败"
    fi
  done
}

##2.expect脚本
#!/usr/bin/expect

set timeout 5
set ip [lindex $argv 0]
set user [lindex $argv 1]
set password [lindex $argv 2]

#复制密钥到目标机器
spawn ssh-copy-id $user@$ip -p 1433
expect {
    "yes/no" {send "yes\r";exp_continue;}
    "password" {send "$password\r";exp_continue;}
}
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!