0

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?

brat
  • 349
  • 3
  • 11
  • 1
    Use `-gt` for numeric comparisons, `>` is for lexicographic comparison. – Barmar Jan 23 '20 at 10:18
  • Should I remove the question? Barmar gave correct solution. But I guess more noobs struggle with bash conditionals being, if this then use that if that then use this unless this corner case etc. I seldom find answers since the questions are so specific to a certain conditional problem so I can seldom apply it to mine. Thanks for the help @Barmar – brat Jan 23 '20 at 10:25
  • You could if you want, but there's no need. – Barmar Jan 23 '20 at 10:26

0 Answers0