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 下如何查看并清理系统内存空间
有时候在服务器上打开了很多会占用内存的程序但关闭这些程序后,发现内存空间还是和没有关闭应用程序时的占用一样,以致使其它应用程序打开时内存不够或很卡,那么此时就想清理掉以前的程序打开时所占用的内存.而大 ...
随机推荐
- 在充电桩联网部署方案中4G DTU的优势是什么
充电桩作为电动汽车充电生态链的一环,具有非常重要的作用,成都远向电子为电动车充电桩.充电站提供专业的无线通信组网产品与技术解决方案,协助充电桩厂家.充电桩运营商.商业充电服务商实现:充电桩设备工作状态 ...
- Django项目-个人网站之投票模块
Django项目之个人网站 关注公众号"轻松学编程"了解更多. Github地址:https://github.com/liangdongchang/MyWeb.git 感兴趣的可 ...
- Raft算法原理剖析
一.复制状态机(replicated state machine) Raft协议可以使得一个集群的服务器组成复制状态机,在详细了解Raft算法之前,我们先来了解一下什么是复制状态机.一个分布式的复制状 ...
- Flink的sink实战之三:cassandra3
欢迎访问我的GitHub https://github.com/zq2599/blog_demos 内容:所有原创文章分类汇总及配套源码,涉及Java.Docker.Kubernetes.DevOPS ...
- 【Azure微服务 Service Fabric 】使用az命令创建Service Fabric集群
问题描述 在使用Service Fabric的快速入门文档: 将 Windows 容器部署到 Service Fabric. 其中在创建Service Fabric时候,示例代码中使用的是PowerS ...
- 优测 x QTA 兼容性测试全面启动啦
鉴于Android系统开放性开发,以及Android系统在智能机市场的覆盖率超高的特点,APP的兼容性测试需求大幅提升.为迎合市场需求,优测(Utest)与QTA合作,全力打造兼容性测试服务.由优测提 ...
- 部署Dotnet Core应用到Kubernetes(二)
前一篇文章,概念性地介绍了K8s的一些基础组件,如Pod.部署和服务.这篇文章,我打算写写如何使用YAML清单定义和配置这些资源. 实际上,在K8s集群中创建对象有几种方式 - 命令,或声明.两种 ...
- Linux 笔记1
linux netstat -an | grep 8081 查看端口进程 window netstat -ano|findstr "1433" taskkill -pid ** - ...
- 处理ceph incompelete的经验
前言 最近已经见到几个环境出现过incompelete了,这个在很久以前Jewel正在合入mark-complete工具的时候就有做过类似的处理,但是随着处理的环境越来越多,这个地方还是有些需要注意的 ...
- Java字符类型(详解)
[1]Java中使用单引号来表示字符常量,字符型在内存中占2个字节. char 类型用来表示在Unicode编码表中的字符.Unicode编码被设计用来处理各种语言的文字,它占2个字节,可允许有655 ...