• Linux下scp命令加强版 优化scp命令 批量对多个Linux主机传输文件


    例如搭建集群或者区块链或者分布式,需要把文件传输到其它多台机器上,而且这个步骤可能会重复n次,通过此脚本即可解决

    Linux批量scp命令执行工具 可批量对多个Linux主机执行传输文件命令 方便省力 适合统一化管理Linux服务器


    所需( expect,sscp.sh,spd )

    #expect是在Tcl基础上创建起来的,所以在安装expect前我们应该先安装Tcl
    
    wget http://nchc.dl.sourceforge.net/sourceforge/tcl/tcl8.4.11-src.tar.gz  
    
    tar xfvz tcl8.4.11-src.tar.gz 
    
    cd tcl8.4.11/unix  
    
    ./configure --prefix=/usr/tcl --enable-shared  
    
    make  
    
    make install  
    
    #安装完毕以后,进入tcl源代码的根目录,把子目录unix下面的tclUnixPort.h copy到子目录generic中
    
    #expect 安装 (需Tcl的库)
    
    
    wget http://sourceforge.net/projects/expect/files/Expect/5.45/expect5.45.tar.gz/download  
    
    tar xzvf download
    
    cd expect5.45  
    
    ./configure --prefix=/usr/expect --with-tcl=/usr/tcl/lib --with-tclinclude=../tcl8.4.11/generic
    
    make  
    
    make install  
    
    ln -s /usr/tcl/bin/expect /usr/expect/bin/expect


    #!/usr/bin/bash
    func_expect(){
     /usr/expect/bin/expect -c "
        set timeout 30;
        spawn $*;
        expect {
              "(yes/no)?" {send "yes
    ";exp_continue}
        	  "*ssword:" {send "$pass
    ";exp_continue}
              #"*~]$" {send "df -h
     exit
    ";interact}
    	}
     "
    }
    
    func_exec(){
     command="scp $1 $2@$3:$4"
     echo -e "33[36m@@@@@@@@@@@@@@@@@@@@@@@@命    令 : $command33[0m"
     func_expect $command
    }
    
    echo '                                                    '
    if [ $# -ne 2 ];then
     echo -e "
    wrong call !
    for eample: $0 file cfg
    "
     exit 1
    else
     sdir='.'
     sfile=$sdir/$1
     echo -e "33[31m########################目    录 : $sdir33[0m"
     echo -e "33[31m########################文    件 : $sfile33[0m"
     echo -e "33[31m########################参数个数 : $#33[0m"
     cat $2 | grep -v '^#' | awk '{print $1,$2,$3,$4,$5}' | while read type ip user pass tdir
      do
       echo '============================================================'
       func_exec $sfile $user $ip $tdir
       sleep 1
      done
    fi
    echo '                                                    '

    ###############################################
    #备注:seq ip/hostname user pass dir###########
    1 f2 root 123  /root/
    2 f3 root 123  /tmp/
    3 192.168.6.203 root 123 /root/
    ###############################################

    直接下载


  • 相关阅读:
    query and join operation after sharding
    Windows Phone中的几种集合控件
    什么是SOPA SOPA的危害
    自动刷新人人网API session_key方法
    Windows Phone XNA创建简单局域网游戏
    static 修饰MySqlConnection引发的异常
    $Dsu$ $on$ $Tree$ 复习
    $Noip$前的小总结哦
    $NOIP2018$ 暴踩全场计划实施方案
    $NOIP2018$ 爆踩全场记
  • 原文地址:https://www.cnblogs.com/llhl/p/9648618.html
Copyright © 2020-2023  润新知