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

     

  • 相关阅读:
    gcc开启C99或C11标准支持
    数组作为参数的四种声明方式
    [BZOJ 2654]tree(陈立杰)
    [HNOI 2014]道路堵塞
    [ZJOI 2006]书架
    [NOI 2010]超级钢琴
    汇编语言语法
    [洛谷P1714]切蛋糕
    [洛谷P1440]求m区间内的最小值
    [NOIP2016 TG D2T3]愤怒的小鸟
  • 原文地址:https://www.cnblogs.com/appresearch/p/6022094.html
Copyright © 2011-2022 走看看