JAR25からデータを取ってくるシェルスクリプト
getby6by.sh
#!/bin/sh
######################################################################
# initialization
######################################################################
set -eu
: ${user:=jra01479}
: ${pass:=*******}
: ${option:="-N -r -nd -np -w 3 --level=0"}
: ${URL:=http://ds.data.jma.go.jp/gmd/jra/download/data/GribFinal} #when by 6hour
#: ${URL:=http://ds.data.jma.go.jp/gmd/jra/download/data/MonthFinal} #when by day or month
: ${prefix:=anl_p} #want data
: ${suffix:=gr}
: ${start:=20110101} #start time
: ${end:=20110229} #finish time
: ${WGET:=wget}
######################################################################
# get JRA-25 data
######################################################################
year=`echo ${start} | cut -c 1-4`
month=`echo ${start} | cut -c 5-6`
day=`echo ${start} | cut -c 7-8` #when by 6hour
hour=00 #when by 6hour
#get control file
mkdir ${start}${prefix}
cd ${start}${prefix}
${WGET} \
${option} \
${user:+--http-user=${user}} \
${pass:+--http-passwd=${pass}} \
${URL}/${prefix}/${year}${month}/${prefix}.ctl
${WGET} \
${option} \
${user:+--http-user=${user}} \
${pass:+--http-passwd=${pass}} \
${URL}/${prefix}/${year}${month}/${prefix}.idx #when by 6hour
#download
while [ ${year}${month}${day} -le ${end} ]
do
${WGET} \
${option} \
${user:+--http-user=${user}} \
${pass:+--http-passwd=${pass}} \
${URL}/${prefix}/${year}${month}/${prefix}.${year}${month}${day}${hour}
#${URL}/${prefix}/${prefix}.${year}${month}.${suffix} #when by day or month
#tomorrow
if [ ${hour} -eq 18 ]; then
hour=00
if [ ${month} -eq 2 ]; then
if [ `expr ${year} % 4` -eq 0 -a \
`expr ${year} % 1000` -ne 0]; then
if [ ${day} -eq 30 ]; then
day=01
month=`echo ${month} | awk '{printf("%02d",$1+1)}'`
rm -f ${prefix}.ctl
rm -f ${prefix}.idx
${WGET} \
${option} \
${user:+--http-user=${user}} \
${pass:+--http-passwd=${pass}} \
${URL}/${prefix}/${year}${month}/${prefix}.ctl
${WGET} \
${option} \
${user:+--http-user=${user}} \
${pass:+--http-passwd=${pass}} \
${URL}/${prefix}/${year}${month}/${prefix}.idx
else
day=`echo ${day} | awk '{printf("%02d",$1+1)}'`
fi
else
if [ ${day} -eq 29 ]; then
day=01
month=`echo ${month} | awk '{printf("%02d",$1+1)}'`
rm -f ${prefix}.ctl
rm -f ${prefix}.idx
${WGET} \
${option} \
${user:+--http-user=${user}} \
${pass:+--http-passwd=${pass}} \
${URL}/${prefix}/${year}${month}/${prefix}.ctl
${WGET} \
${option} \
${user:+--http-user=${user}} \
${pass:+--http-passwd=${pass}} \
${URL}/${prefix}/${year}${month}/${prefix}.idx
else
day=`echo ${day} | awk '{printf("%02d",$1+1)}'`
fi
fi
elif [ ${month} -eq 04 -o ${month} -eq 06 -o \
${month} -eq 09 -o ${month} -eq 11 ]; then
if [ ${day} -eq 31 ]; then
day=01
month=`echo ${month} | awk '{printf("%02d",$1+1)}'`
rm -f ${prefix}.ctl
rm -f ${prefix}.idx
${WGET} \
${option} \
${user:+--http-user=${user}} \
${pass:+--http-passwd=${pass}} \
${URL}/${prefix}/${year}${month}/${prefix}.ctl
${WGET} \
${option} \
${user:+--http-user=${user}} \
${pass:+--http-passwd=${pass}} \
${URL}/${prefix}/${year}${month}/${prefix}.idx
else
day=`echo ${day} | awk '{printf("%02d",$1+1)}'`
fi
else
if [ ${day} -eq 32 ]; then
day=01
if [ ${month} -eq 12 ]; then
month=01
year=`expr ${year} + 1`
else
month=`echo ${month} | awk '{printf("%02d",$1+1)}'`
fi
rm -f ${prefix}.ctl
rm -f ${prefix}.idx
${WGET} \
${option} \
${user:+--http-user=${user}} \
${pass:+--http-passwd=${pass}} \
${URL}/${prefix}/${year}${month}/${prefix}.ctl
${WGET} \
${option} \
${user:+--http-user=${user}} \
${pass:+--http-passwd=${pass}} \
${URL}/${prefix}/${year}${month}/${prefix}.idx
else
day=`echo ${day} | awk '{printf("%02d",$1+1)}'`
fi
fi
else
hour=`echo ${hour} | awk '{printf("%02d",$1+6)}'`
fi
done
exit 0
0 件のコメント:
コメントを投稿