I an writing simple script in Bash, to check Linux file system disk usage on root file system and display a warning message if system is greater than 6%.
The commands are running in a terminal, however when I tried the if
statement, I am getting this error on line 16
[: missing
]'`
1 #!/bin/bash
2
3
4
5 clear
6 #checking for usage on the system and saving in a file usage1
7 df -h / >usage1
8
9 #display current use to the screen
10 clear
11 echo
12 awk '$5>6' usage1
13
14 #Creating variable to use in the awk if statemant
15 usage2= "awk '{print $5}'/home/peters/usage1 | tail -n1 |cut -c1"
16 #Building statemant
17 if ($usage2>6)
18 print "Warning file system greater than 6% !!"
19
20 exit 0
usage2=$(awk blah blah)
, and line 17(( usage2 > 6 ))
and if you open anif
you require afi
to close it... – jasonwryan Jul 27 '15 at 02:11usage1
and/home/peters/usage1
the same file? I assumer they are (but I'm not sure.. it is a bit odd either way) -- It seems that you can check it in one line:[[ -n $(df -h / | awk 'int($5)>6{print $5}') ]] && echo "Warning file system greater than 6%"
– Peter.O Jul 27 '15 at 04:29usage="$( awk '($5+0>6){print $5}' usage1 )"
Force numerical value by adding 0. 2.- Change line 13 toecho "$usage"
. 3.- Comment line 15. 4.- Change line 17 toif [[ $usage -gt 6 ]]; then
. 5.- The commandprint
does not print values, echo does. change line 18 toecho "Warning file system greater than 6% !!"
. Add line 19:fi
. – Jul 28 '15 at 04:15