check_for_free_space() {
local space=${1}
local path=${2}
+ local space_in_path=0
- # Space needs to passed in MB
- # df returns bytes so we multiple by 1024
- space=$(( ${space} * 1024 ))
-
- log debug $(df --output=avail ${path} | tail -n 1)
+ space_in_path=$(df -h -B MB --output=avail ${path} | tail -n 1)
+ space_in_path=${space_in_path%MB}
+ log debug ${space_in_path}
log debug ${space}
- if [ $(df --output=avail ${path} | tail -n 1) -lt ${space} ]; then
+ if [ ${space_in_path} -lt ${space} ]; then
log error "Not enough free space available under ${path}"
- log error "Free space is $(df -h -B MB --output=avail ${path} | tail -n 1) but we need at least $(( ${space} / 1024 / 1024 ))MB"
+ log error "Free space is ${space_in_path}MB but we need at least ${space}MB"
return ${EXIT_ERROR}
fi
}