linux脚本实现scp命令,shell通过scp命令实现简单数据推送

第一部分:获取数据路径#!/bin/bash

#GetPath.sh

#用途:获取某天到某天,某个时间段的数据路径

#路径输出到path.txt文件中

###################Step One.####################

>path.txt

function traceInfoWriter

{

echo -e "\033[40m\033[1;36m"$*"\033[0m"

}

function usage

{

traceInfoWriter "Usage:"

traceInfoWriter "$0 -d date -{例:20170101-20171231}- -h hour -{例:00-24}-"

traceInfoWriter "-d: date range.(20170101-20171231) "

traceInfoWriter "-h: hour range.(00-24)"

traceInfoWriter "-H: help info"

traceInfoWriter "Example: sh $0 -d 20170501-20170612 -h 02-08"

exit

}

[[ 0 -eq $# ]] && usage

while getopts "d:h:H" ARG

do

case $ARG in

d)

export Date=$OPTARG

;;

h)

export Hour=$OPTARG

;;

H)

usage

;;

?)

echo "Unkonw argument!"

echo "Only -d -h -H options are supported~"

exit 1

esac

done

stime=${Date:0:8}

etime=${Date:9:17}

sh=${Hour%-*}

eh=${Hour##*-}

if [[ $stime -gt $etime  ]] || [[ $sh -gt $eh  ]]

then

echo "Error format."

exit 1

fi

while :

do

for i in `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.txt 2> /dev/null

done

stime=$(date -d "$stime 1day"  +%Y%m%d)

if [[ $stime -gt $etime ]]; then

break;

fi

done

第二部分:通过scp传输数据#!/bin/bash

#TransferData.sh

#读取path.txt文件传输数据

#remotepath目标服务器路径

##################Step Two#################

user=gsics

host=10.24.173.162

passwd=gsics03

remotepath="/home/gsics/user/wangp/data"

for filepath in `cat path.txt`

do

expect -c "

set timeout 30

spawn scp $filepath $user@$host:${remotepath}

expect {

\"*yes/no\" { send \"yes\r\"; exp_continue }

\"*?assword:\" { send \"$passwd\r\" }

}

interact

"

done

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值