I am learning shell, I want to use shell script to check disk space and output value, but it doesn't work.
#!/bin/bash
result=""
ALERT=40
OUT_FLAG() {
local check_value=$1
local result_value=$2
if [ ${check_value} -eq 0 ];then
result="$result|${result_value}:0"
else
result="$result|${result_value}:1"
fi
}
Check_disk() {
local disk_result=0
df -Pl | grep -vE "^Filesystem|tmpfs|cdrom" | awk '{print $5 " " $6}'|while read output;
do
usep=$(echo $output | awk '{ print $1}' | cut -d'%' -f1)
if [ $usep -ge $ALERT ]; then
disk_result=1
fi
done
OUT_FLAG ${disk_result} "disk"
}
Check_disk
echo $result
I want it to output |disk:1 but it is |disk:0. Wanted to know if it's good practice to do that and what would be the best way to do that?