auto scp

#!/bin/bash

#for i in $@
#do
#    echo $i
#done

length=$#
if  [ $length -lt 3 ]; then
    echo "param not enought"
    exit -1
fi

#arr=($*)
#length=${#arr[@]}
#psd=${arr[$(($length-1))]}
#dst=${arr[$(($length-2))]}
#src=${arr[@]:0:$(($length-3))}
src=$1
dst=$2
psd=$3
port=$4
if [ "$port" == "" ];then
    port=22
fi

expect<<- END

set timeout -1

spawn scp -P $port -r $src $dst

expect {
 "(yes/no"
   {
    send "yes\n"
    expect "*assword:" { send "$psd\n"}
   }
 "*assword:"
 {
   send "$psd\n"
 }
}

expect eof

catch wait result
exit [lindex \$result 3]

END

ret=$?

# echo "[info] auto_scp ret $ret"
exit $ret

你可能感兴趣的:(linux)