#!/bin/sh

#set -x
required_free_percentage=93

percent_free=`df -h | grep /dev/mapper/data-graphite | awk '{print $5}' | sed 's/%//'`

echo ${percent_free}

i=365

while [ ${percent_free} -gt ${required_free_percentage} ]
do
#echo ${i}
find /var/lib/carbon/whisper/ -type f -mtime +${i}  | xargs -n1 -r rm
percent_free=`df -h | grep /dev/mapper/data-graphite | awk '{print $5}' | sed 's/%//'`
#echo ${percent_free}
i=$(( $i -1 ))
done