shell通过scp命令实现简单数据推送

前端之家收集整理的这篇文章主要介绍了shell通过scp命令实现简单数据推送前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

第一部分:获取数据路径@H_403_4@

#!/bin/bash
#GetPath.sh
#用途:获取某天到某天,某个时间段的数据路径
#路径输出到path.txt文件中
###################StepOne.####################
>path.txt
functiontraceInfoWriter
{
echo-e"\033[40m\033[1;36m"$*"\033[0m"
}
functionusage
{
traceInfoWriter"Usage:"
traceInfoWriter"$0-ddate-{例:20170101-20171231}--hhour-{例:00-24}-"
traceInfoWriter"-d:daterange.(20170101-20171231)"
traceInfoWriter"-h:hourrange.(00-24)"
traceInfoWriter"-H:helpinfo"
traceInfoWriter"Example:sh$0-d20170501-20170612-h02-08"
exit
}
[[0-eq$#]]&&usage
whilegetopts"d:h:H"ARG
do
case$ARGin
d)
exportDate=$OPTARG
;;
h)
exportHour=$OPTARG
;;
H)
usage
;;
?)
echo"Unkonwargument!"
echo"Only-d-h-Hoptionsaresupported~"
exit1
esac
done
stime=${Date:0:8}
etime=${Date:9:17}
sh=${Hour%-*}
eh=${Hour##*-}
if[[$stime-gt$etime]]||[[$sh-gt$eh]]
then
echo"Errorformat."
exit1
fi
while:
do
foriin`seq-s""-w$sh$eh`
do
ls/FY4/FY4A/AGRI/L1/FDI/DISK/2017/$stime/FY4A-_AGRI--_N_DISK_*E_L1-_*-_MULT_NOM_${stime}${i}*_*_4000M_V0001.HDF>>path2.txt2>/dev/null
done
stime=$(date-d"$stime1day"+%Y%m%d)
if[[$stime-gt$etime]];then
break;
fi
done

第二部分:通过scp传输数据@H_403_4@

#!/bin/bash
#TransferData.sh
#读取path.txt文件传输数据
#remotepath目标服务器路径
##################StepTwo#################
user=gsics
host=10.24.173.162
passwd=gsics03
remotepath="/home/gsics/user/wangp/data"
forfilepathin`catpath.txt`
do
expect-c"
settimeout30
spawnscp$filepath$user@$host:${remotepath}
expect{
\"*yes/no\"{send\"yes\r\";exp_continue}
\"*?assword:\"{send\"$passwd\r\"}
}
interact
"
done

猜你在找的Bash相关文章