#!/bin/bash
# Corrida diaria Modelos y rutinas SPOA
#
CLOGFILE=/opt/spoa/log/caribbean.log
GFS_NFILES=21
#Cantidad de archivos a descargar
# GFS_DATAP=/spoa/WRFV33/WPS/GFS_DATA
GFS_DATAP=/home/slonin/WRFV33/WPS/GFS_DATA
GFS_FTP=/spoa/data/gfs/$(date '+%Y%m%d')
LOGFILE=/opt/spoa/log/caribbean.log
# WRF_PATH=/spoa/WRFV33/WRFV3/run
WRF_PATH=/home/slonin/WRFV33/WRFV3/run
GFSFTPP=gfs.$(date '+%Y%m%d')00 # "gfs.2011121600"
DOM="1"
HOST=1
# 201208278: Eliminar log anterior si existe!
# if [ -f "$CLOGFILE" ]; then
# rm $CLOGFILE
# fi
#2012: leer la cantidad de dominios a procesar
for i in "$@"; do
if [ $i == '-dom=2' ]; then
DOM="2"
fi
if [ $i == '-host=2' ]; then
HOST=2
fi
done
ftpstat=`ncftpget -r1 ftpprd.ncep.noaa.gov . /pub/data/nccf/com/gfs/prod/$GFSFTPP 2>&1 > /dev/null | grep 'Connection timed out'`
# ftpstat=`ncftpget -r1 ftpprd.ncep.noaa.gov . /pub/data/nccf/com/gfs/prod/$GFSFTPP 2>&1 > /dev/null | grep 'Not a regular file'`
# if [ $ftpstat == "Connection timed out" ]; then exit 1; fi
if [ -n "${ftpstat}" ]; then
echo "No hay acceso al servidor FTP en este momento!, Finalizando script!!!"
exit 1
fi
# echo "Disabling DRBD Peers on Canete & Copiapo"
# sudo /sbin/drbdadm --stacked disconnect drbd0-U
# sudo /sbin/drbdadm -- disconnect drbd0
echo "Now is time for Download GFS data `date +%H:%M:%S`"
cd /spoa/scripts/python
if [ $HOST -eq 1 ]; then
# python gfsdown.py -type wrf #bajar datos GFS y preparar namelists WRFCaribbean
python gfsdown.py -type wrf -dom=$DOM
else
python gfsdown.py -type wrf -dom=$DOM -host=$HOST
fi
#20120210: bajar datos GFS y preparar namelists WRFCaribbean para dominio y subdom Cartagena
# python gfsdown.py -type wrf >> $LOGFILE #bajar datos GFS y preparar namelists WRFCaribbean
# 20100930: VALIDACION DE TAMANO PROMEDIO ACEPTABLE DE LOS DATOS GFS DESCARGADOS
# DE ELLO DEPENDERA SI LOS MODELOS SE EJECUTARAN
cd $GFS_DATAP
countgfs=`ls -l|awk '/'"$(date '+%b %e')"'/ {print $9}'|wc -l`
#Cuenta la cantidad de ficheros descargados a la fecha, deben ser igual a GFS_NFILES
if [ $countgfs -eq $GFS_NFILES ]; then
mkdir $GFS_FTP # crea folder para guardar GFS data del dia
## 20130920: Disable GFS file size validation
## 20131030: Enable GFS file local copy
gfsvectr=(`ls -l|awk '/'"$(date '+%b %e')"'/ {print $9}'`)
# gfsintgr=1
for gfsf in "${gfsvectr[@]}"; do
# gfsze=`stat -c%s $gfsf`
# echo -e "$gfsf\\t$gfsze" >> $LOGFILE
# if [ $gfsf = "gfs.t00z.pgrb2f00" ]; then
# if [ $gfsze -gt 43000000 ]; then
cp -a $gfsf $GFS_FTP
# continue
# else
# gfsintgr=0
# break
# fi
# else
# if [ $gfsze -gt 47000000 ]; then
# cp -a $gfsf $GFS_FTP
# continue
# else
# gfsintgr=0
# break
# fi
# fi
done
#if [ $gfsintgr -eq 1 ]; then
echo "Ejecutando SPOA Caribbean"
echo "1" > ~/gfsready
# enviando 1 a ~/gfsready para ejecutar WRFPacific!
cd /spoa/scripts/bash
echo "Time for SPOA Caribbean at `date +%H:%M:%S`"
# ./caribbean.sh < /dev/null 2>&1 #1 domain
./caribbean.sh -dom=$DOM < /dev/null 2>&1
# 20120830: resetear estado de gfsready a 0
# echo "0" > ~/gfsready
# echo "Copia de Ficheros GFS a ODESSA:$GFS_DATAP"
# scp -p $GFS_DATAP/* root@odessa:$GFS_DATAP
# echo "Lanzando tarea remota caribbean.sh en ODESSA!"
# pdsh -w root@odessa "/spoa/scripts/bash/caribbean.sh -dom=2 < /dev/null 2>&1 > /tmp/caribbean.out&"&
# ./caribbean02.sh -dom=2 < /dev/null 2>&1 #SPOA for generate domain & subdomain
# echo "Time for SPOA Pacific at `date +%H:%M:%S`"
#./pacific.sh
#else
## echo "0" > ~/gfsready
## # enviando 0 a ~/gfsready NO ejecutara WRFPacific!
## echo "La descarga de datos GFS no es correcta, reintente manualmente mas tarde!"
## # 20120828: Enviar un correo notificando la novedad!
## python /spoa/scripts/python/smtp.py "GFS Download Failed" "La descarga de datos GFS no es correcta, reintente mas tarde!"
#fi
else
echo "0" > ~/gfsready
# enviando 0 a ~/gfsready NO ejecutara WRFPacific!
echo " No cumple con los $GFS_NFILES necesarios!, reintente mas tarde"
python /spoa/scripts/python/smtp.py "GFS Download Failed" "No cumple con los $GFS_NFILES necesarios! reintente mas tarde"
fi
exit 1
Comments