#!/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