echo "---------------INICIO SOLO CONTRUYENDO LOS LATESTS---------------" 

echo $0
cd "$(dirname "$0")"
echo $(date)
. ./config.cfg  ##include configuration file

#
echo $(date +"%Y-%m-%d %T")
echo  "Generar GEOJSON"
echo  "-----------"
$gdal_path/ogr2ogr -f "GeoJSON" $glm_path/clusters.geojson PG:"host=154.12.253.150 port=11014 user=geodb password=geoUniversal$%1 dbname=geodb" -sql "SELECT * from goes_glm_cluster"
echo "clusters"
$gdal_path/ogr2ogr -f "GeoJSON" $glm_path/city_in_cluster.geojson PG:"host=154.12.253.150 port=11014 user=geodb password=geoUniversal$%1 dbname=geodb" -sql "SELECT * from goes_glm_city_in_cluster" -lco ENCODING=UTF-8
echo "city_in_cluster"
$gdal_path/ogr2ogr -f "GeoJSON" $glm_path/city_distance.geojson PG:"host=154.12.253.150 port=11014 user=geodb password=geoUniversal$%1 dbname=geodb" -sql "SELECT * from goes_glm_city_distance" 
echo "city distance"
$gdal_path/ogr2ogr -f "GeoJSON" $glm_path/latest.geojson PG:"host=154.12.253.150 port=11014 user=geodb password=geoUniversal$%1 dbname=geodb" -sql " select *,extract(epoch from now() at time zone 'utc' - fecha_hora)/60 elapsed,(extract(epoch from now() at time zone 'utc' - fecha_hora)/60/5)::integer min_group from goes_glm where fecha_hora >=(now() at time zone 'utc' - INTERVAL '20 minutes') order by fecha_hora" 
echo "Latest"
echo $(date +"%Y-%m-%d %T")