CentOS下构建Shell简易分发系统
bash经典收集
经典收集1
for f in `(cd .; find suite -type f | grep -v SCCS)`; \
do \
d=/usr/local/mysql/mysql-test/`dirname $f`; \
mkdir -p $d ; \
/usr/bin/install -c -m 644 ./$f $d ; \
done
test -z "/usr/local/mysql/mysql-test" || mkdir -p -- "/usr/local/mysql/mysql-test"
expect
自动登录expect脚本
[root@nginx sbin]# cat 1.expect
#!/usr/bin/expect
set host "192.168.211.135"
set passwd "root123"
spawn ssh root@$host
expect {
"yes/no" { send "yes\r";exp_continue }
"assword:" { send "$passwd\r" }
}
interact
[root@nginx sbin]#
自动登录后执行命令
[root@nginx sbin]# cat 2.expect
#!/usr/bin/expect
set user "root"
set host "192.168.211.135"
set passwd "root123"
spawn ssh $user@$host
expect {
"yes/no" { send "yes\r";exp_continue }
"assword:" { send "$passwd\r" }
}
expect "]*"
send "touch /tmp/12.ext\r"
expect "]*"
send "echo 1212 >/tmp/12.txt\r"
expect "]*"
send "exit\r"
#interact
[root@nginx sbin]#
expect脚本传递参数
[root@nginx sbin]# cat 3.expect
#!/usr/bin/expect
set user [lindex $argv 0]
set host [lindex $argv 1]
set passwd "root123"
set cm [lindex $argv 2]
spawn ssh $user@$host
expect {
"yes/no" { send "yes\r" }
"password:" { send "$passwd\r" }
}
expect "]*"
send "$cm\r"
expect "]*"
send "exit\r"
[root@nginx sbin]#
[root@nginx sbin]# ./3.expect root 192.168.211.135 "ls /root/"
自动同步文件脚本
[root@nginx sbin]# cat 4.expect
#!/usr/bin/expect
set passwd "root123"
spawn rsync -av root@192.168.211.135:/tmp/12.txt /tmp/
expect {
"yes/no" { send "yes\r" }
"password:" { send "$passwd\r" }
}
expect eof
[root@nginx sbin]#
构建简易文件分发系统
适用于有多台机器需要同时更新文件
[root@nginx sbin]# cat rsync.expect
#!/usr/bin/expect
set passwd "root123"
set host [lindex $argv 0]
set file [lindex $argv 1]
spawn rsync -av $file root@$host:/
expect {
"yes/no" { send "yes\r" }
"password:" { send "$passwd\r" }
}
expect eof
[root@nginx sbin]#
[root@nginx sbin]# cat ip.list
192.168.211.135
192.168.211.137
[root@nginx sbin]#
[root@nginx sbin]# cat rsync.sh
#!/bin/bash
for ip in `cat ip.list`
do
echo $ip
[ -x rsync.expect ] || chmod a+x rsync.expect
./rsync.expect $ip ip.list
done
[root@nginx sbin]#
命令批量执行脚本
适用于有多台机器需要批量执行命令
[root@nginx sbin]# cat exe.expect
#!/usr/bin/expect
set host [lindex $argv 0]
set passwd "root123"
set cm [lindex $argv 1]
spawn ssh root@$host
expect {
"yes/no" { send "yes\r" }
"password:" { send "$passwd\r" }
}
expect "]*"
send "$cm\r"
expect "]*"
send "exit\r"
[root@nginx sbin]#
[root@nginx sbin]# cat ip.list
192.168.211.135
192.168.211.137
[root@nginx sbin]#
[root@nginx sbin]# cat exe.sh
#!/bin/bash
for ip in `cat ip.list`
do
echo $ip
[ -x exe.expect ] || chmod a+x exe.expect
./exe.expect $ip "w;free -m;ls /tmp"
done
[root@nginx sbin]#
CentOS下构建Shell简易分发系统的更多相关文章
- shell项目-分发系统-构建文件分发系统
shell项目-分发系统-构建文件分发系统 需求背景对于大公司而言,肯定时不时会有网站或者配置文件更新,而且使用的机器肯定也是好多台,少则几台,多则几十甚至上百台.所以,自动同步文件是至关重要的. 实 ...
- Linux centosVMware运行告警系统、分发系统-expect讲解、自动远程登录后,执行命令并退出、expect脚本传递参数、expect脚本同步文件、指定host和要同步的文件、shell项目-分发系统-构建文件分发系统、分发系统-命令批量执行
一运行告警系统 创建一个任务计划crontab -e 每一分钟都执行一次 调试时把主脚本里边log先注释掉 再次执行 没有发现502文件说明执行成功了,每日有错误,本机IP 负载不高 二.分发系统-e ...
- shell项目-分发系统-expect讲解
shell项目-分发系统-expect讲解 yum install -y expect 1. 自动远程登录 #! /usr/bin/expect set host "192.168.133. ...
- CentOS下编写shell脚本来监控MySQL主从复制的教程
这篇文章主要介绍了在CentOS系统下编写shell脚本来监控主从复制的教程,文中举了两个发现故障后再次执行复制命令的例子,需要的朋友可以参考下 目的:定时监控MySQL主从数据库是否同步,如果不同步 ...
- Windows下本机简易监控系统搭建(Telegraf+Influxdb+Grafana)
一.文件准备 1.1 文件名称 telegraf-1.2.1_windows_amd64.zip influxdb-1.2.2_windows_amd64.zip grafana-4.2.0.wind ...
- Windows下本机简易监控系统搭建(Telegraf+Influxdb+Grafana)--转
原文地址:http://www.cnblogs.com/liugh/p/6683488.html 一.文件准备 1.1 文件名称 telegraf-1.2.1_windows_amd64.zip in ...
- centos 下构建lamp环境
构建准备: 1.配置防火墙,开启80端口.3306端口 vi /etc/sysconfig/iptables -A INPUT -m state --state NEW -m tcp -p tcp - ...
- CentOS下如何用nmon收集系统实时运行状况
#赋予执行权限 chmod +x nmon 执行./nmon可以查看实时的系统状态有提示的,d看磁盘,n看网络,c看cpu #如果不想看实时的,想收集系统长时间运行情况然后分析,可用这个 nohup ...
- CentOS 下如何查看并清理系统内存空间
有时候在服务器上打开了很多会占用内存的程序但关闭这些程序后,发现内存空间还是和没有关闭应用程序时的占用一样,以致使其它应用程序打开时内存不够或很卡,那么此时就想清理掉以前的程序打开时所占用的内存.而大 ...
随机推荐
- Nginx 配置请求响应时间
1.常见默认nginx.conf配置日志格式 log_format main '$remote_addr - $remote_user [$time_local] "$request&quo ...
- python测试报告输出 htmltestrunner 及 中文乱码的解决方式
下载HTMLTestRunner.py 第三方库 下载地址: python2:http://tungwaiyip.info/software/HTMLTestRunner.html 右键另存为下载HT ...
- 《Web接口开发与自动化测试》学习笔记(一)
一.Django的入门 学习思路:先安装Django,然后在建立一个项目,接着运行这个项目,最后修改一下这个项目的数据,学习一下Django的原理之类的. 1.安装Django $pip instal ...
- 对hadoop之RPC的理解
因为公司hadoop集群出现了一些瓶颈,在机器不增加的情况下需要进行优化,不管是存储还是处理性能,更合理的利用现有集群的资源,所以来学习了一波hadoop的rpc相关的知识和hdfs方面的知识,以及y ...
- windows本地破解用户口令
实验所属系列:操作系统安全 实验对象: 本科/专科信息安全专业 相关课程及专业:信息网络安全概论.计算机网络 实验时数(学分):2学时 实验类别:实践实验类 实验目的 1.了解Windows2000/ ...
- 3.2spring源码系列----循环依赖源码分析
首先,我们在3.1 spring5源码系列--循环依赖 之 手写代码模拟spring循环依赖 中手写了循环依赖的实现. 这个实现就是模拟的spring的循环依赖. 目的是为了更容易理解spring源码 ...
- fork系统调用关于如何让子进程先运行{wait(),waitpid(),sleep()}
在父进程里面调用wait()和waitpid()可以确保子进程先运行,因为当子进程运行完后会变成僵尸进程,此时会发送一个信号给父进程,父进程接受到信号才会运行. 有人或许会问如果在父进程调用wait之 ...
- 154. Find Minimum in Rotated Sorted Array II(循环数组查找)
Suppose an array sorted in ascending order is rotated at some pivot unknown to you beforehand. (i.e. ...
- Flink处理函数实战之一:深入了解ProcessFunction的状态(Flink-1.10)
欢迎访问我的GitHub https://github.com/zq2599/blog_demos 内容:所有原创文章分类汇总及配套源码,涉及Java.Docker.Kubernetes.DevOPS ...
- backfill和recovery的最优值
ceph在增加osd的时候会触发backfill,让数据得到平均,触发数据的迁移 ceph在移除osd的时候需要在节点上进行数据的恢复,也有数据的迁移和生成 只要是集群里面有数据的变动就会有网卡流量, ...