1200字范文,内容丰富有趣,写作的好帮手!
1200字范文 > Linux下scp命令加强版 优化scp命令 批量对多个Linux主机传输文件

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

时间:2023-04-20 20:02:51

相关推荐

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

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

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

所需( expect,sscp.sh,spd)

expect的安装(参考资料博客园)

#expect是在Tcl基础上创建起来的,所以在安装expect前我们应该先安装Tclwget http://nchc./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 /projects/expect/files/Expect/5.45/expect5.45.tar.gz/download tar xzvf downloadcd expect5.45 ./configure --prefix=/usr/expect --with-tcl=/usr/tcl/lib --with-tclinclude=../tcl8.4.11/genericmake make install ln -s /usr/tcl/bin/expect /usr/expect/bin/expect

sscp.sh脚本

#!/usr/bin/bashfunc_expect(){/usr/expect/bin/expect -c "set timeout 30;spawn $*;expect {\"(yes/no)?\" {send \"yes\r\";exp_continue}\"*ssword:\" {send \"$pass\r\";exp_continue}#\"*~]\$\" {send \"df -h\r exit\r\";interact}}"}func_exec(){command="scp $1 $2@$3:$4"echo -e "\033[36m@@@@@@@@@@@@@@@@@@@@@@@@命 令 : $command\033[0m"func_expect $command}echo ' 'if [ $# -ne 2 ];thenecho -e "\nwrong call !\nfor eample: $0 file cfg\n"exit 1elsesdir='.'sfile=$sdir/$1echo -e "\033[31m########################目 录 : $sdir\033[0m"echo -e "\033[31m########################文 件 : $sfile\033[0m"echo -e "\033[31m########################参数个数 : $#\033[0m"cat $2 | grep -v '^#' | awk '{print $1,$2,$3,$4,$5}' | while read type ip user pass tdirdoecho '============================================================'func_exec $sfile $user $ip $tdirsleep 1donefiecho ' '

spd文件

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

直接下载

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。