# sample file
#datafiles-to-be-deleted-20201127.checked

source ~/.bashrc

# this script checks if there are scheduled deletion files generated by the checker
# sample usage: only the paths where are the files are needed
# ./schedule_free_space.sh /home/Earth/jberlin/Development/dqc_results/

source ~/.bashrc

# Filter
if [[ -z "$1" ]] ; then
    echo "No path supplied"
    exit 1
fi
path_results=$1

# get the current date
current_date=$(date '+%Y%m%d')
scheduled_deletion_file=${path_results}/datafiles-to-be-deleted-${current_date}.checked
echo ${scheduled_deletion_file}
if [[ -f ${scheduled_deletion_file} ]] ; then
   # read the content of the file
   # secure that we are only deleting grib files
   while IFS= read -r datafile
   do
      if [[ -f ${datafile} ]] ; then
        echo "deleting ${datafile}"
        # rm ${datafile}
      fi
   done < "${scheduled_deletion_file}"
   # remove the file after processing it without errors
   #rm ${scheduled_deletion_file}
else
  echo "nothing to delete on ${current_date}"
fi