zoukankan      html  css  js  c++  java
  • 快速做所有主机相互认证

    脚本:

    #!/usr/bin/expect
    spawn sensors-detect
    for {set i 0} {$i<=10} {incr i} {
    expect ":"
    send "
    "
    }
    interact
    

    解释:
    spawn是启动命令
    for为循环的写法
    interact为退出
    这个脚本目的是在一次运行过程中不断模拟用户的enter操作

    设置免密码交互

    #!/bin/bash
    
    if [ ! -f "/root/.ssh/id_rsa" ]; then
    
    /usr/bin/expect <<-EOF
    spawn ssh-keygen
    expect {  
        "*save the key (/root/.ssh/id_rsa" { send "
    "; exp_continue }  
        "*(empty for no passphrase)" { send "
    "; exp_continue }  
        "*same passphrase again" { send "
    ";}  
    }  
    interact  
    expect eof
    EOF
    fi
    
    for host in `cat /etc/hosts|awk '{print $1}'`
    do
    
    passwd="ubuntu"
    /usr/bin/expect <<-EOF
    spawn ssh-copy-id root@$host
    
    expect {  
        "*yes/no" { send "yes
    "; exp_continue }  
        "*password:" { send "$passwd
    " }
        " All keys were skipped because they already exist on the remote system." {send "
    "}
    }  
    interact  
    expect eof
    EOF
    
    done
    
    

    把host文件传到所有机器
    先从第一台主机做做配置跟其他机器的交互
    然后seq把脚本传递到其他所有机器
    然后用seq 循环ssh 远程执行脚本

    变更记录

    Why Who When
    创建 武汉-运维-磨渣 2013-8-12
    更新 武汉-运维-磨渣 2015-3-23
    更新所有主机交互 武汉-运维-磨渣 2019-3-29
  • 相关阅读:
    03 重定向,请求转发,cookie,session
    02 http,servlet,servletconfig,HttpServletRequest ,HttpServletResponse
    02 JDBC相关
    01 mysql
    16 反射,枚举,新特性
    13 递归练习
    12 IO流
    11 异常
    兼容当前五大浏览器的渐变颜色背景gradient的写法
    Electron Browser加载iframe(webview src属性)
  • 原文地址:https://www.cnblogs.com/zphj1987/p/13575273.html
Copyright © 2011-2022 走看看