#!/bin/bash -x #input is an empty text file with the date to be processed in the filename, e.g. date_2003-01-01.txt input=$1 indir=$2 outdir=$3 Rfile=$4 date=$(basename $input .txt | cut -d'_' -f2) yr=${date:0:4} fn_date=$(sed 's#-##g' <<<$date) yr_mn=${fn_date:0:6} echo $fn_date cp ${indir}/swat_${yr_mn}*.tif . ls . if [ ! -f ${outdir}/swat_${fn_date}_monthly_sum.tif ]; then mkdir -p output/ mkdir -p rtemp/ TMPDIR=rtemp/ #run r script to calculate frequency of surface water occurrence echo "Rscript $Rfile "$date" "swat"" Rscript $Rfile "$date" "swat" rm -rf rtemp/ mv swat_${fn_date}_monthly_sum.tif output/swat_${fn_date}_monthly_sum.tif else echo "${outdir}/swat_${fn_date}_monthly_sum.tif already exists" fi exit 0