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简易分发系统的更多相关文章

  1. shell项目-分发系统-构建文件分发系统

    shell项目-分发系统-构建文件分发系统 需求背景对于大公司而言,肯定时不时会有网站或者配置文件更新,而且使用的机器肯定也是好多台,少则几台,多则几十甚至上百台.所以,自动同步文件是至关重要的. 实 ...

  2. Linux centosVMware运行告警系统、分发系统-expect讲解、自动远程登录后,执行命令并退出、expect脚本传递参数、expect脚本同步文件、指定host和要同步的文件、shell项目-分发系统-构建文件分发系统、分发系统-命令批量执行

    一运行告警系统 创建一个任务计划crontab -e 每一分钟都执行一次 调试时把主脚本里边log先注释掉 再次执行 没有发现502文件说明执行成功了,每日有错误,本机IP 负载不高 二.分发系统-e ...

  3. shell项目-分发系统-expect讲解

    shell项目-分发系统-expect讲解 yum install -y expect 1. 自动远程登录 #! /usr/bin/expect set host "192.168.133. ...

  4. CentOS下编写shell脚本来监控MySQL主从复制的教程

    这篇文章主要介绍了在CentOS系统下编写shell脚本来监控主从复制的教程,文中举了两个发现故障后再次执行复制命令的例子,需要的朋友可以参考下 目的:定时监控MySQL主从数据库是否同步,如果不同步 ...

  5. 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 ...

  6. Windows下本机简易监控系统搭建(Telegraf+Influxdb+Grafana)--转

    原文地址:http://www.cnblogs.com/liugh/p/6683488.html 一.文件准备 1.1 文件名称 telegraf-1.2.1_windows_amd64.zip in ...

  7. centos 下构建lamp环境

    构建准备: 1.配置防火墙,开启80端口.3306端口 vi /etc/sysconfig/iptables -A INPUT -m state --state NEW -m tcp -p tcp - ...

  8. CentOS下如何用nmon收集系统实时运行状况

    #赋予执行权限 chmod +x nmon 执行./nmon可以查看实时的系统状态有提示的,d看磁盘,n看网络,c看cpu #如果不想看实时的,想收集系统长时间运行情况然后分析,可用这个 nohup ...

  9. CentOS 下如何查看并清理系统内存空间

    有时候在服务器上打开了很多会占用内存的程序但关闭这些程序后,发现内存空间还是和没有关闭应用程序时的占用一样,以致使其它应用程序打开时内存不够或很卡,那么此时就想清理掉以前的程序打开时所占用的内存.而大 ...

随机推荐

  1. [Luogu P2824] [HEOI2016/TJOI2016]排序 (线段树+二分答案)

    题面 传送门:https://www.luogu.org/problemnew/show/P2824 Solution 这题极其巧妙. 首先,如果直接做m次排序,显然会T得起飞. 注意一点:我们只需要 ...

  2. 【SpringBoot】14. SpringBoot多环境配置

    SpringBoot多环境配置 Spring Boot 1.5.19.RELEASE 假设项目中需要3个环境--开发.测试.生产 profile :代表的就是一个环境变量 语法结构:applicati ...

  3. JavaSE基础语法学习-异常

    异常 异常指程序运行中出现的不期而至的各种状况,如:文件找不到.网络连接失败.非法参数等. 异常发生在程序运行期间,它影响了正常的程序执行流程. 比如说,你的代码少了一个分号,那么运行出来结果是提示是 ...

  4. python00

    # Python* [什么是 Python 生成器?](#什么是-Python-生成器)* [什么是 Python 迭代器?](#什么是-Python-迭代器)* [list 和 tuple 有什么区 ...

  5. 3.java设计模式之工厂模式

    基本需求: 一个披萨店需要订购不同种类的披萨 传统方式: 实现思路 在订购类中根据用户不同的输入直接创建不同的披萨实体类进行返回 UML类图 代码实现 披萨类 // 抽象父类 public abstr ...

  6. Pandas_工资集处理

    import numpy as np import pandas as pd from pandas import Series,DataFrame # 1--读取数据文件 file_obj=open ...

  7. day001|python基础回顾

    1.python是一门编程语言 编程语言是人与计算机能够沟通的一种语言 人----------编程语言---------计算机 2.编程是: ①人将要做的事的步骤想清楚 ②找计算机能够听懂的语言将步骤 ...

  8. netfilter 的扩展功能 helper tftp-nat

    /* 需要对conntrack进行功能扩展的协议,会初始化一个struct nf_conntrack_helper 实例,把该实例注册到Netfilter中管理的全局哈希表中. 查找helper使用的 ...

  9. 最长回文子串的Manacher算法

    对于一个比较长的字符串,O(n^2)的时间复杂度是难以接受的.Can we do better? 先来看看解法2存在的缺陷. 1) 由于回文串长度的奇偶性造成了不同性质的对称轴位置,解法2要对两种情况 ...

  10. 手写一个Web服务器,极简版Tomcat

    网络传输是通过遵守HTTP协议的数据格式来传输的. HTTP协议是由标准化组织W3C(World Wide Web Consortium,万维网联盟)和IETF(Internet Engineerin ...