expect一键批量拷贝

来源:互联网 发布:nginx rewrite是什么 编辑:程序博客网 时间:2024/05/16 12:50

#!/bin/sh

local_file=$1

remote_dir=$2

if [ $# -ne 2 ];then

echo "usage:$0 argv2"

echo "must two argvs"

exit

fi


[ -f ~/.ssh/known_hosts ] && > ~/.ssh/known_hosts


for ip in `cat iplist.bak`

do

[ ! -d ~/.ssh/ ] && mkdir -p ~/.ssh && touch ~/.ssh/known_hosts

function NO_PASSORD()

{

expect -c "

#spawn ssh -p22 $ip free -m

spawn scp "${local_file}" root@$ip:"${remote_dir}"

//注意这里应该设置一个合适的过期时间,否则,若数据量过大时,无法拷贝数据

set timeout 60

expect \"(yes/no)\"

send \"yes\r\"

expect \"password:\"

send \"123456\r\"

expect eof"

}

NO_PASSORD

done

0 0
原创粉丝点击