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. Java集合(类)框架(二)

    1.Set集合 1.1 HashSet集合 HashSet底层为哈希码 不是数组,因此没有下标的概念,也就不能根据下标来查询某个元素 存放元素无序,不可重复 1.1.1 声明 Set<Strin ...

  2. iptables基础原理和使用简介

    概念简介 名称 Netfilter/iptables模块有两部分组成: Netfilter框架以及iptables,iptables又分为iptables(内核空间)和iptables命令行工具(用户 ...

  3. numpy的统计分析

    一.排序 间接排序(argsort,lexsort) 根据一个或多个数据集进行排序 1.Sort() --对数值直接进行排序 a.一维排序 b.二维排序 c.axis的认知 2.argsort() - ...

  4. C# 2 新增语法特性

    C# 2.0 ,.NET Framework 2.0,.NET Framework 3.0,Visual Studio 2005 C#2主要添加了泛型.匿名方法,分部类型(类.结构.接口),可空类型, ...

  5. 记EF的一个基本访问类

    代码: 1 using EFModel; 2 using System; 3 using System.Collections.Generic; 4 using System.Data.Entity; ...

  6. php 获取抖音id

    <?php public function getid($dy_url){ $header=get_headers($dy_url); $str = "/^.*?(\d+).*/&qu ...

  7. python文档自译:os模块-01【说明部分】

    15.1. os - Miscellaneous operating system interfaces This module provides a portable way of using op ...

  8. IP 层收发报文简要剖析6--ip_forward 报文转发

    //在函数ip_route_input_slow->ip_mkroute_input注册, /* * IP数据包的转发是由ip_forward()处理,该函数在ip_rcv_finish() * ...

  9. 部署Dotnet Core应用到Kubernetes(二)

    前一篇文章,概念性地介绍了K8s的一些基础组件,如Pod.部署和服务.这篇文章,我打算写写如何使用YAML清单定义和配置这些资源.   实际上,在K8s集群中创建对象有几种方式 - 命令,或声明.两种 ...

  10. REDHAT 7.5beta 新推出的VDO功能

    前言 关于VDO VDO的技术来源于收购的Permabit公司,一个专门从事重删技术的公司,所以技术可靠性是没有问题的 VDO是一个内核模块,目的是通过重删减少磁盘的空间占用,以及减少复制带宽,VDO ...