1200字范文,内容丰富有趣,写作的好帮手!
1200字范文 > linux脚本批量复制文件 shell实现scp批量下发文件

linux脚本批量复制文件 shell实现scp批量下发文件

时间:2019-05-13 19:29:59

相关推荐

linux脚本批量复制文件 shell实现scp批量下发文件

本文系统CentOS6.0

Expect是Unix系统中用来进行自动化控制和测试的软件工具,由Don Libes制作,作为Tcl脚本语言的一个扩展,应用在交互式软件中如telnet,ftp,Passwd,fsck,rlogin,tip,ssh等等。该工具利用Unix伪终端包装其子进程,允许任意程序通过终端接入进行自动化控制;

1、安装

1 yum install expect expect-devel -y

2、编写Script

#!/usr/bin/expect

if {$argc < 2} {

send_user "usage: $argv0 src_file username ip dest_file password\n"

exit

}

set src_file [lindex $argv 0]

set username [lindex $argv 1]

set host_ip [lindex $argv 2]

set dest_file [lindex $argv 3]

set password [lindex $argv 4]

spawn scp -r $src_file $username@$host_ip:$dest_file

expect {

"(yes/no)?"

{

send "yes\n"

expect "*assword:" {send "$password\n"}

}

"*assword:"

{

send "$password\n"

}

}

expect "100%"

expect eof

3、用法实例:

[root@master ~]# ./allscp.sh install.log root 192.168.100.145 /tmp/ 123456

你也可以使用其他帐号;

上面实现了对单台机器复制;

4、批量服务器复制

#!/bin/bash

src_file=$1

username=$2

host_list=$3

dest_file=$4

password=$5

cat $host_list | while read line

do

host_ip=`echo $line | awk '{print $1}'`

./allscp.sh $src_file $username $host_ip $dest_file $password

done

用法实例:

希望大家有更好的介意~

推荐阅读:

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