folderpath="/pdffolder/"
declare -a fileext
fileext[0]="*.pdf"
mainpath=$folderpath${fileext[0]}
if [ ! -d "$folderpath" ]; then
# critical error, no pdf folder
echo "CRITICAL: PDF FOLDER NOT FOUND"
echo "CRITICAL: PDF FOLDER NOT FOUND" >&2
exit 2
fi
numberofpdfs=`ls -la $mainpath | wc -l`
if [ "$(($numberofpdfs))" -eq 0 ]
then
# critical error, no pdf files
echo "CRITICAL: NO PDF FILES FOUND"
echo "CRITICAL: NO PDF FILES FOUND" >&2
exit 2
fi
latestfilefullpath=`find $folderpath -type f -name "*.pdf" -printf "%T+\t%p\n" | sort -r| head -n 1`
latestfile=`echo $latestfilefullpath | rev | cut -d"/" -f1 | rev` #removes folders from the path
# the function below will try to find if this pdf file was modifed less than 7 days and 8 hours ago
numberofnewpdfs=`find $mainpath -type f -name "$latestfile" -newermt '-10560 minutes'| wc -l`
if [ "$(($numberofnewpdfs))" -eq 0 ]
then
# not critical error, old pdf files
echo "WARNING: LATEST PDF IS MORE THAN 7 DAYS OLD"
echo "WARNING: LATEST PDF IS MORE THAN 7 DAYS OLD" >&2
exit 1
fi
echo "PDFs ARE UP-TO-DATE"
exit 0