need help with disk check script

I wrote a script that checks particular device path directory which is full or more than 90% used, and will search older file inside and delete it. My code looks like this:

#!/usr/bin/ksh
ref=90

df -k | grep /cbmdata/00/gdd | tr -d '%' | \
while read a b c d e other
do

 if (( $e >= $ref )) && continue
 then
 line=`find /cbmdata/00/gdd -name "LOGS*" |sort -nr |tail -1`
    # echo $line
    rm -f $line
 fi

done

it works but not good, sometimes it only deletes only one file whereas I want it check the disk size and if more than 90 % in use go and delete another old file..it uses cronjob to timing...

Could you please advise me how can I make my script more robust or porfessional ? Thanks :confused:

Try this (untested :)):

#!/usr/bin/ksh
ref=90

while [ 1 ] 
do
  df -k | grep /cbmdata/00/gdd | tr -d '%' | \
  read a b c d e other
  if (( "$e" >= "$ref" ))
  then
    line=`find /cbmdata/00/gdd -name "LOGS*" |sort -nr |tail -1`
    # echo $line
    rm -f $line
  else
    exit 0
  fi
done

Regards

I tested it\ and seems to be working well/
I need to test for some time
Thanks :slight_smile:

You really should try to move the find command outside the while loop, it is the slowest part of your program and really only needs to be done once.

If your script was in ksh I would have suggested using a co-process and using 'read -p' however it is not, so you could do this by using a temporary file or a named pipe.

ok, I ll try thank