Hi Folks!
Simple noob bashscript to show diskspace left in the computer.
#!/bin/bash
result=$(df --total | tail -n 1)
echo $result
result2=$(echo "$result" | sed -e "s/\s\+/,/g")
echo $result2
result3=$(echo "$result2" | cut -f 5 -d ',')
echo $result3
result4=$(echo "$result3" | tr -d '%')
echo $result4
if [[ $result4 > 50 ]]
then
echo "WARNING!!! Disk space: ${result4}%"
elif [[ $result4 > 30 ]]
then
echo "Warning!!! Disk space: ${result4}%"
elif [[ $result4 > 10 ]]
then
echo "Alert! Disk space: ${result4}%"
elif [[ $result4 > 5 ]]
then
echo "Is this ok? Disk space: ${result4}%"
elif [[ $result4 > 3 ]]
then
echo "Disk space: ${result4}%"
else
echo "Disk space: OK"
fi
Problem/Question I know that there is less memory used then 10% using: df --total "manualy" Yet the output of the script when running: sudo ./nameofscript.sh keeps returning:
Alert! Disk space 2%
Can anyone see reason why?