#!/bin/bash -x

#d=$(date +"%Y%m%d")
d=$1

kill -9 $(ps auxwwww | grep baixa_merca | grep -v $$ | awk '{print $2}')
kill -9 $(ps auxwwww | grep lftp | awk '{print $2}')

mkdir -p /dados/forcatarefa/mercator/new/daily/${d}

cd /dados/forcatarefa/mercator/new/daily/${d}
if [ $(ps auxwwww | grep wget | grep PSY4QV3R1 | wc -l) -eq 0 ]; then
	kill -9 $(ps auxwwww | grep wget | grep PSY4QV3R1 | awk '{print $2}')
	wget -c ftp://tr_cptec2019_049:MOiinpe1445@ftp.mercator-ocean.fr/PSY4QV3R1/${d}/ext-PSY4QV3R1_1*
fi

#cd /dados/forcatarefa/mercator/new/daily
#for arq in $(lftp -u td_cptec2019_049,MOiinpe1445 ftp.mercator-ocean.fr -e "dir /daily/${arq}; quit" | grep nc | awk '{print $9}'); do
#   echo ${arq}
#   lftp -u td_cptec2019_049,MOiinpe1445 ftp.mercator-ocean.fr -e "pget -c -n3 /daily/${arq}; quit"
#done

mkdir -p /dados/forcatarefa/mercator/new/hourly
cd /dados/forcatarefa/mercator/new/hourly
for arq in $(lftp -u td_cptec2019_049,MOiinpe1445 ftp.mercator-ocean.fr -e "dir /hourly/${arq}; quit" | grep nc | awk '{print $9}'); do
   echo ${arq}
   lftp -u td_cptec2019_049,MOiinpe1445 ftp.mercator-ocean.fr -e "pget -c -n3 /hourly/${arq}; quit"
done

exit 0
