linux shell 数据下载,shell多线程实现从ftp下载数据

#!/bin/bash

function DownLoad()

{

local url=$1

local dirpath=$2

wget --ftp-user=gsics  --ftp-password=gsics \

-c -r -q -e  robots=off --reject="index.html*"  \

--tries=5 \

--timeout=20 \

--waitretry=10 \

--wait=3 \

--no-parent \

-nd -nH --dont-remove-listing \

--directory-prefix=${dirpath} \

${url}

}

psname=$0

psNum=`ps aux |grep ${psname}|wc -l`

if [ $psNum -gt 3 ]

then

cdir=`pwd`

echo 'Process is Running .' >${cdir}/tmp.log

echo `date` >>${cdir}/tmp.log

exit

fi

DATADIR=/nas03/v6/AQUA/MODIS/L1/ORBIT

thread=5

if [ $# -eq 2 ];then

stime=$1

etime=$2

else

stime=`date --date="-16 day"  +%Y%m%d`

etime=`date --date="-1 day" +%Y%m%d`

fi

let Flag=0

while :

do

if [ ${Flag} -eq 1 ];then

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

fi

let Flag=1

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

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

break

fi

cat > ftpawx33.tmp <

user gsics gsics

as

cd /AQUA/MODIS/L1/ORBIT/${stime:0:6}

nlist

quit

EOF

echo ${stime}

jjj=`date -d "${stime}" +%j`

ftp -v -n -i  10.0.66.33  ftpnamelist33.info

cat ftpnamelist33.info | grep "^MYD" | grep ".A${stime:0:4}${jjj}" | grep ".006." >namelist33.txt

if [[ ! -s namelist33.txt ]]

then

continue;

fi

if [ ! -d  $DATADIR/${stime:0:6} ]

then

mkdir -p $DATADIR/${stime:0:6}

fi

DirPath=$DATADIR/${stime:0:6}/

declare -a order_array

let jj=0

for Name in `cat namelist33.txt`

do

url=ftp://10.0.66.33:/AQUA/MODIS/L1/ORBIT/${stime:0:6}/$Name

order_array[$jj]=${url}

let jj=${jj}+1

done

if [ ${#order_array[@]} -eq 0 ];then

unset ${order_array}

continue

fi

tmp_fifofile="/tmp/$$.fifo"

mkfifo  $tmp_fifofile

exec 6<> $tmp_fifofile

rm  $tmp_fifofile

for  ((i=0 ;i

do

echo

done >&6

for  ((i = 0 ;i 

do

read -u6

{

DownLoad ${order_array[$i]} ${DirPath}

echo >&6

}&

done

wait

exec  6>&-

unset ${order_array}

done

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值