#!/bin/bash
# Remote Copy file
# date 20160821
username=root
passwd=123456
usage(){
echo "Usage:sh `basename $0` -f [hostlist] Local_file Remote_file"
exit 1
}
while getopts ":f:" optname
do
case "$optname" in
f|-f)
file=$OPTARG
;;
*)
usage
;;
esac
done
shift $(($OPTIND-1))
src_file="$1"
# Remote Copy file
# date 20160821
username=root
passwd=123456
usage(){
echo "Usage:sh `basename $0` -f [hostlist] Local_file Remote_file"
exit 1
}
while getopts ":f:" optname
do
case "$optname" in
f|-f)
file=$OPTARG
;;
*)
usage
;;
esac
done
shift $(($OPTIND-1))
src_file="$1"
dest_file="$2"
if [ -z $src_file ] || [ -z $dest_file ] ;then
usage
fi
if [ ! -f $file ] ;then
echo "Host file $file does not exist"
exit
fi
for ip in `cat $file`
do
/usr/bin/expect<<EOF
set timeout 10
spawn scp -r $src_file $username@$ip:$dest_file
expect {
"*yes/no" { send "yes\r"; exp_continue}
"*password:" { send "$passwd\r" }
}
expect "100%"
expect eof
EOF
done