zoukankan      html  css  js  c++  java
  • 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 ";exp_continue }

    "assword:" { send "$passwd " }

    }

    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 ";exp_continue }

    "assword:" { send "$passwd " }

    }

    expect "]*"

    send "touch /tmp/12.ext "

    expect "]*"

    send "echo 1212 >/tmp/12.txt "

    expect "]*"

    send "exit "

    #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 " }

    "password:" { send "$passwd " }

    }

    expect "]*"

    send "$cm "

    expect "]*"

    send "exit "

    [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 " }

    "password:" { send "$passwd " }

    }

    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 " }

    "password:" { send "$passwd " }

    }

    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 " }

    "password:" { send "$passwd " }

    }

    expect "]*"

    send "$cm "

    expect "]*"

    send "exit "

    [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]#

     

  • 相关阅读:
    Java开发之富文本编辑器TinyMCE
    将博客搬至CSDN
    利用Docker搭建java项目开发环境
    Linux上传和下载之Xshell
    JSP中利用JSTL标签对日期格式化
    MySQL数据库localhost的root用户登陆遭遇失败
    CentOS7下 简单安装和配置Elasticsearch Kibana Filebeat 快速搭建集群日志收集平台(版本6.x)
    CentOS下递归遍历文件夹下所有文件,查找指定字符
    谷歌浏览器插件不让离线安装怎么办?
    X-Forwarded-For 会少记录一次代理服务器的IP
  • 原文地址:https://www.cnblogs.com/appresearch/p/6022094.html
Copyright © 2011-2022 走看看