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 下如何查看并清理系统内存空间
有时候在服务器上打开了很多会占用内存的程序但关闭这些程序后,发现内存空间还是和没有关闭应用程序时的占用一样,以致使其它应用程序打开时内存不够或很卡,那么此时就想清理掉以前的程序打开时所占用的内存.而大 ...
随机推荐
- 初始化vue项目
1.创建vue项目命令 vue init webpack deaxios # 使用脚手架创建项目 deaxios(项目名,随便取得) cd deaxios # 进入项目 npm install axi ...
- Java的类加载器有几种?什么是双亲委派机制?
一.JAVA类加载器包括几种? 启动类加载器 bootstrap class loader 启动类加载器主要加载的是JVM自身需要的类,这个类加载是用C++语言实现的,是虚拟机自身的一部分,它负责将 ...
- 硬核卸载Vue(删除)
第一步 查找vue位置 打开 cmd 输入 where vue 第二步 进入文件 直接cv(复制粘贴) 随便打开个文件 第三步 删除vue 删除前缀vue的所有 进入node_modules 删除@v ...
- XJOI 夏令营501-511NOIP训练18 高二学堂
在美丽的中山纪念中学中,有座高二学堂,同样也是因为一个人,让它们变 成了现在这个样子~那就是我们伟大的级主任.因为他,我们又迎来了一个木有电影,只有对答案的段考日:又迎来了一个不是大礼拜,而是小礼拜的 ...
- Java_基础(一)
注释 单行注释: // 多行注释: /*开头, */结尾, 可跨行, 可嵌入 public static void main(String[] args/* 哈哈 */) 文档注释: /** 开头, ...
- 子线程调用invalidate()产生“Only the original thread that created a view hierarchy can touch its views.”原因分析
目录 1.异常出处 2.从View.invalidate()方法开始分析 3.ViewRootImpl如何与View进行关联:从Activity的setContentView开始分析 3.1 最顶层的 ...
- php执行exec、xsell_exec命令失败
在php.ini下进行更改 查找disable_function 去掉exec xsell_exec 重启php
- Spider--补充_None_global_urlparse
# 知识点补充: # 1) None: a = None if a: print("非None") else: print("None") if a is no ...
- Pandas_数据清洗与整理_全
# 数据清洗与整(全) # 1) 常见的数据清洗方法 # 2) 数据合并:多源数据的合并和连接 # 3) 数据重塑:针对层次化索引,学会 stack和 unstack # 4) 字符串处理:学会 Da ...
- jdk包结构及用途分析
Table of Contents 概述 jdk包总览 rt.jar包结构分析 概述 jdk是每一个使用java的人员每一天都在使用的东西,博主也已经研究了jdk源代码中的一些类了,本篇博客是想从jd ...