jeudi 27 août 2015

Download files with wget. If wget downloads files, move them, otherwise use wget to download different files

I am trying to run a shell script that includes if statements and a set of initial conditions. If wget downloads the files, I would like the script to check if the files with the "grib2" extension exists in the folder. if the files do exist, then it moves them to another directory. If after running wget the files don't download or exist in the directory, then I would like wget to download from a different source. The script is meant to filter.

The issue I am encountering is the second wget script never runs, even if there are zero files with that extension in the folder.

#!/bin/sh

#
# variables
#

basedir="http://ift.tt/1PATK9X"
basename1="hur/prod/hur."

date=`date +"%Y%m%d"`
date1=`date +"%Y%m%d" -d "+1 days"`
date2=`date +"%Y%m%d" -d "-1 days"`
hour=`date +"%H"`
file=`ls -l /awips2/edex/data/gfdl/*.grib2 2>/dev/null`
#
# main
#

if [ $hour -ge "13" ] && [ $hour -le "18" ]
then
datetime="${date}12"
url1="${basedir}/${basename1}${datetime}/"
wget -r -nd --no-parent -e robots=off -R 'index.*' -A '*9*l*.0p16.*.grib2' -P /awips2/edex/data/gfdl/ $url1 
   if [[ "$file" != "0" ]]; then
   mv /awips2/edex/data/gfdl/* /awips2/edex/data/manual/
   else [[ "$file" != "1" ]]; then
   wget -r -nd --no-parent -e robots=off -R 'index.*' -A '*0*l*.0p16.*.grib2' -P /awips2/edex/data/gfdl/ $url1
   mv /awips2/edex/data/gfdl/* /awips2/edex/data/manual/
   fi



elif [ $hour -ge "19" ] && [ $hour -le "23" ]
then
datetime="${date}18"
url1="${basedir}/${basename1}${datetime}/"
wget -r -nd --no-parent -e robots=off -R 'index.*' -A '*9*l*.0p16.*.grib2' -P /awips2/edex/data/gfdl/ $url1 
   if [[ "$file" != "0" ]]; then
   mv /awips2/edex/data/gfdl/* /awips2/edex/data/manual/
   else [[ "$file" != "1" ]]; then
   wget -r -nd --no-parent -e robots=off -R 'index.*' -A   '*0*l*.0p16.*.grib2' -P /awips2/edex/data/gfdl/ $url1
   mv /awips2/edex/data/gfdl/* /awips2/edex/data/manual/
   fi
fi

Aucun commentaire:

Enregistrer un commentaire