SSH批量管理
 expect自动交互

原创博文http://www.cnblogs.com/elvi/p/7662908.html

# SSH批量管理
# expect自动交互 #############################
#!/bin/sh
# 初次使用,以root批量执行 CMD=(
date
uname -r
hostname
) sh ${[*]} . /etc/init.d/functions
[[ -f /usr/bin/expect ]] || { echo "install expect";yum install expect -y; } #若没expect则安装
########## #############################
# #SSH批量执行shell命令
#!/bin/sh
. /etc/init.d/functions
[[ $# == ]] && { echo 'ege: /bin/sh '$' "命令1;命令2"';exit; }
for n in
do
echo
ssh -p22 192.168..$n $*
[[ $? == ]] && action "========IP:192.168.20.$n========" /bin/true || action "========IP:192.168.20.$n========" /bin/false
done
########## #############################
###批量推送文件
#!/bin/sh
. /etc/init.d/functions
[[ $# == ]] && { echo 'ege: /bin/sh '$' "本地文件" "(远程)目录"';exit; }
for n in
do
scp -P22 $ sshync@192.168..$n ~/ >/dev/null >& &&\
ssh -p22 -t sshync@192.168..$n sudo rsync ~/$ $ >/dev/null >&
[[ $? == ]] && action "========IP:192.168.20.$n" /bin/true || action "========IP:192.168.20.$n" /bin/false
done
########## #############################
#!/bin/sh
# 批量分发SSHKEY . /etc/init.d/functions
[[ -f /usr/bin/expect ]] || { echo "install expect";yum install expect -y; } #若没expect则安装 PUB=/`whoami`/.ssh/id_dsa.pub
[[ -f $PUB ]] || { ssh-keygen -t dsa -P '' -f /`whoami`/.ssh/id_dsa>/dev/null >&; } #若没公钥则生成 USER=sshync
PASS=sshync
# IP : SIP + SIP_end
SIP=192.168..
SIP_end=( ) #expect自动交互
function EXP() {
/usr/bin/expect << EOF
set timeout
spawn ssh-copy-id -i $PUB "-p22 $USER@$SIP$n"
expect {
"yes/no" { send "yes\r";exp_continue }
"password:" { send "$PASS\n";exp_continue }
eof { exit }
}
EOF
}
#
[[ $ == y ]] || { echo -e 'ege: /bin/sh '$' y \n 当前'`whoami`'用户向远程用户'$USER'分发SSHKEY \n 远程主机列表'$SIP''${SIP_end[*]}' \n';exit; } for n in ${SIP_end[*]}
do
EXP |grep '.ssh/authorized_keys'>/dev/null >&
[[ $? == ]] && action "========IP:192.168.20.$n" /bin/true || action "========IP:192.168.20.$n" /bin/false
done #############################
#!/bin/sh
#Made by elven,
# MariaDB初始化,设置密码 DBPass=db2017
[[ -f /usr/bin/expect ]] || { echo "install expect";yum install expect -y; } #若没expect则安装
/usr/bin/expect << EOF
set timeout
spawn mysql_secure_installation
expect {
"enter for none" { send "\r"; exp_continue}
"Y/n" { send "Y\r" ; exp_continue}
"password:" { send "$DBPass\r"; exp_continue}
"new password:" { send "$DBPass\r"; exp_continue}
"Y/n" { send "Y\r" ; exp_continue}
eof { exit }
}
EOF
#测试
mysql -u root -p$DBPass -e "show databases;"
#############################

SSH批量管理 expect自动交互的更多相关文章

  1. linux 的 expect 自动交互

    https://www.jianshu.com/p/0194cbd70d39 https://www.cnblogs.com/saneri/p/10819348.html  参考 expect是一个自 ...

  2. 脚本_使用expect自动交互远程主机安装软件

    #!bin/bash#功能:使用expect工具自动交互密码,远程到其它主机,安装httpd软件#作者:liusingbon#删除~/.ssh/known-hosts后,ssh远程任何主机,系统都会询 ...

  3. Linux Expect自动交互脚本

    https://likegeeks.com/expect-command/ In the previous post, we talked about writing practical shell ...

  4. (转)SSH批量分发管理&非交互式expect

    目录 1 SSH批量分发管理 1.1 测试环境 1.2 批量管理步骤 1.3 批量分发管理实例 1.3.1 利用sudo提权来实现没有权限的用户拷贝 1.3.2 利用sudo提权开发管理脚本 1.3. ...

  5. (转)Linux SSH批量分发管理

    Linux SSH批量分发管理 原文:http://blog.51cto.com/chenfage/1831166 第1章 SSH服务基础介绍 1.1 SSH服务 1.1.1SSH介绍 SSH是Sec ...

  6. Shell编程之Expect自动化交互程序

    一.Expect自动化交互程序 1.spawn命令 通过spawn执行一个命令或程序,之后所有的Expect操作都会在这个执行过的命令或程序进程中进行,包括自动交互功能. 语法: spawn [ 选项 ...

  7. Expect自动化交互程序

    Expect介绍: 1.什么是Expect Expect是一个用来实现自动化交互功能的软件套件,基于TCL的脚本编程工具语言,方便学习,功能强大. 2.为什么要使用expcet: 当今的企业运维中,自 ...

  8. Linux Shell 自动交互功能

    需求背景:   近日,在安装某软件过程,发现在安装过程需要输入一些信息才能继续下一步操作,在机器数量较少情况下,我们可以单台登录上去完成安装操作,但当机器数量超过一定时,如果再手动登录操作,就会产生大 ...

  9. [转]expect实现ssh自动交互

    shell脚本实现ssh自动登录远程服务器示例: #!/usr/bin/expect spawn ssh root@192.168.22.194 expect "*password:&quo ...

随机推荐

  1. JS中OOP之模拟封装和继承和this指向详解

    大家好,今天我带大家学习一下js的OOP, 大家都知道,面向对象有三个基本特征,继承,封装和多态,面向对象的语言有那么几种,C++,PHP,JAVA等,而功能强大的JS可以模拟实现面向对象的两大特征, ...

  2. UWP Popup 弹出

    一:需求 做一个类似于安卓的弹出消息框,如图.当用户点击下载或者选择时,能够从底部弹出一个提示框,用于提示用户. 二:Popup 类 不需要我们自己额外去写一个弹窗类,微软自己有一个Popup 弹窗类 ...

  3. JavaScript深入之call和apply的模拟实现

    call 一句话介绍 call: call() 方法在使用一个指定的 this 值和若干个指定的参数值的前提下调用某个函数或方法. 举个例子: var foo = { value: 1 }; func ...

  4. 点击下拉,其余不动的jquery事件(转)

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...

  5. Leetcode题解(20)

    59. Spiral Matrix II 题目 这道题copy网上的代码 class Solution { private: ][]; ][]; public: void dfs(int dep, v ...

  6. Fibonacci Numbers

    Fibonacci Numbers Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) T ...

  7. 暑假练习赛 007 A - Time

    A - Time Description standard input/outputStatements A plane can go from city X to city Y in 1 hour ...

  8. Python基础学习参考(一):python初体验

    一.前期准备 对于python的学习,首先的有一个硬件电脑,软件python的运行环境.说了一句废话,对于很多初学者而言,安装运行环境配置环境变量的什么的各种头疼,常常在第一步就被卡死了,对于pyth ...

  9. MongoDB入门系列(一):基础概念和安装

    概述 MongoDB是目前非常流行的一种非关系型数据库,作为入门系列的第一篇本篇文章主要介绍Mongdb的基础概念知识包括命名规则.数据类型.功能以及安装等. 环境: OS:Windows Versi ...

  10. Spring各jar包作用及依赖

    先附spring各版本jar包下载链接http://repo.spring.io/release/org/springframework/spring/ spring.jar 是包含有完整发布模块的单 ...