Never Say Die

やんなっちゃうけれど、いいことあんのも、人生。そうやって生きてくんだ。

【シェルスクリプト】まとめてネットからデータをダウンロードする。

面倒くさいことは、スクリプトにおまかせしよう!

 

ということで、100個くらいあるデータをwgetコマンドを使ってネットからダウンロードしないといけない。

しかし、いちいち、1つずつコマンドを売っていては埒があかないので、スクリプトの勉強がてら、ちょっと作ってみました。

 

 #! /bin/sh                                                                                
#                                                                                         

rm *.fits

WGET=$(which wget)
which wget > /dev/null
if [ $? != 0 ]; then
  echo Error : wget is not available.
  exit 1
fi

# Website address where the files are located                                             
url="http://○○○.html" #downlod URL

option="-nc -np -w 3"
#option="-N -r -np -w 3 -nd --level=0"                                                    


for i in `seq 19 89`; do
inlist="l0"$i"a.fits" #file name                                                          
${WGET} ${option} ${url}/${inlist}
done


こんな感じ。まぁ初めて作った本格的なスクリプトにしてはよくできた方かなと。