expect分发脚本
【分发系统】yum -y install expect
#!/usr/bin/expect
set host "192.168.11.102"
set passwd ""
spawn ssh root@$host
expect {
"yes/no" { send "yes\r"; exp_continue}
"assword:" { send "$passwd\r" }
}
interact
###############
#!/usr/bin/expect
set user "root"
set passwd ""
spawn ssh $user@192.168.11.18
expect {
"yes/no" { send "yes\r"; exp_continue}
"password:" { send "$passwd\r" }
}
expect "]*"
send "touch /tmp/12.txt\r"
expect "]*"
send "echo 1212>/tmp/12.txt\r"
expect "]*"
send "exit\r"
#################
#!/usr/bin/expect
set user [lindex $argv ]
set host [lindex $argv ]
set passwd ""
set cm [lindex $argv ]
spawn ssh $user@$host
expect {
"yes/no" { send "yes\r"}
"password:" { send "$passwd\r" }
}
expect "]*"
send "$cm\r"
expect "]*"
send "exit\r"
#######
#!/usr/bin/expect
set passwd ""
set host [lindex $argv ]
set file [lindex $argv ]
spawn rsync -av $file root@$host:$file
expect {
"yes/no" { send "yes\r"}
"password:" { send "$passwd\r" }
}
expect eof
执行: ./4.expect 192.168.11.18 /tmp/12.txt第二部分:构建文件分发系统1. 需求背景对于大公司而言,肯定时不时会有网站或者配置文件更新,而且使用的机器肯定也是好多台,少则几台,多则几十甚至上百台。所以,自动同步文件是至关重要的。2. 实现思路首先要有一台模板机器,把要分发的文件准备好,然后只要使用expect脚本批量把需要同步的文件分发到目标机器即可。3. 核心命令rsync -av --files-from=list.txt / root@host:/4. 文件分发系统的实现cat rsync.expect
#!/usr/bin/expect
set passwd ""
set host [lindex $argv ]
set file [lindex $argv ]
spawn rsync -av --files-from=$file / root@$host:/
expect {
"yes/no" { send "yes\r"}
"password:" { send "$passwd\r" }
}
expect eof
cat ip.list
192.168.11.18
192.168.11.19
......
cat rsync.sh
#!/bin/bash
for ip in `cat ip.list`
do
echo $ip
./rsync.expect $ip list.txt
done
5. 命令批量执行脚本cat exe.expect
#!/usr/bin/expect
set host [lindex $argv ]
set passwd ""
set cm [lindex $argv ]
spawn ssh root@$host
expect {
"yes/no" { send "yes\r"}
"password:" { send "$passwd\r" }
}
expect "]*"
send "$cm\r"
expect "]*"
send "exit\r"
cat exe.sh
#!/bin/bash
for ip in `cat ip.list`
do
echo $ip
./exe.expect $ip "w;free -m;ls /tmp"
done
expect分发脚本的更多相关文章
- (转)expect命令脚本语言介绍及生产实践
原文:http://www.fblinux.com/?p=526 Expect介绍 expect是一个用来实现自动交互功能的软件套件,是用来实现自动和交互式任务程序进行通信,无需人的手工干预.比如SS ...
- ssh无密登录_集群分发脚本xsync
1.ssh免密登录 ssh ip地址 [root@192 ~]# ssh 192.168.1.102 root@192.168.1.102's password: Last login: Mon Fe ...
- Shell 分发脚本
目录 Shell分发脚本 原理 rsync命令分析 特点 基本语法 实现 需求 环境变量 脚本实现 知识点 获得当前路径的目录dirname 获得当前路径的文件名basename shell远程执行命 ...
- expect 分发ssh key脚本
#!/usr/bin/expect } { send_user "USAGE:expect_sshkey.exp host" exit } #define var set host ...
- linux文件分发脚本
1.说明 此脚本可分发两类文件,1.固定内容文件,2.(每台被分发主机)内容不同的文件 ppp.sh为拨号脚本,每台被分发主机内容不同 根据分发文件名字不同(ppp.sh和其他文件)自动选择分发方式 ...
- SCCM2012分发脚本
1.分发批处理脚本 命令行:script.bat 2.分发PowerShell脚本 命令行:PowerShell.exe -executionpolicy unrestricted -file .\s ...
- Expect 小脚本
简介: Expect 可以替系统管理员完成与系统的交互式操作 shell > yum -y install expect # 可以通过 yum 安装 shell > which expec ...
- linux shell脚本中使用expect(脚本打开新终端自动远程连接顺便输一点指令)(巨坑)
放弃吧 我找了六个小时都没找到可以用的方案(指标题括号里的内容) 给个曲线救国的方法: 现把expect脚本写成一个文件 在另一个shell脚本中调用
- ssh秘钥免交互批量分发脚本
将以下内容保存为.sh文件后运行即可,需根据各自情况修改ip_up和ip_arr #!/bin/bash #脚本功能:ssh秘钥免交互批量分发 #制 作 人:罗钢 联系方式:278554547@qqc ...
随机推荐
- How to Get the Length of File in C
How to get length of file in C //=== int fileLen(FILE *fp) { int nRet = -1; int nPosBak; nPosBak = f ...
- Fix: The account is not authorized to log in from this station
If you have more the one computers running Windows, then its possible to connect them using HomeGrou ...
- 关于BigDecimal小记
昨天在写一个关于金额计算的时候,随手用了BIgDecimal结果出问题了,如下图NO.3那样,期望值是10.00,结果是10.1... 后来发现犯了一个想当然的错误,那就是两个参数的构造方法是这样的, ...
- 【#】Spring3 MVC 注解(二)---@RequestMapping
博客分类: spring MVC 1 问题:有多个 @RequestMapping @controller @RequestMapping("/aaa") ...
- mybatis 传参是 list<string> 的注意事项
<!--付款 批量 修改账单状态--><update id="editbillpayALL" parameterType="java.util.List ...
- [GO]errorr接口的使用
package main import ( "fmt" "errors" ) func main() { erro1 := fmt.Errorf("% ...
- 15 输入三个整数x,y,z,请把这三个数由小到大输出。
题目:输入三个整数x,y,z,请把这三个数由小到大输出. public class _015ThreeNumberSort { public static void main(String[] arg ...
- Hadoop Shell
1.常用的一些Shell 再好的博客,都不如官方文档好用: http://hadoop.apache.org/docs/r1.0.4/cn/hdfs_shell.html
- Open Type vs Open resource
Open Type 可查询所有java 类型,包括.java .class Open Resource 只能打开 .java 等 ,不能打开 .class 相同点 都可以使用 ? * 通配符
- top命令查看进程列表
top命令查看进程列表 top命令是linux下常用的性能分析工具,能实时显示系统中各个进程的资源占用状况.和win的资源管理器类似.top是一个动态显示过程,即可以通过用户按键来不断刷新当前状态,如 ...