In the following sccript I want to be able to only send different notifications based in whether the filesyste is over 80% or 90%. I need help with if [ ]. How would I make it so that if a filesystem was over 80% but less than 90% only do one thing. The way I currently have it setup I end up getting double notifications when a filesystem is over 90%.
# Notification message
root_msg="FileSystem `df -h / | tail -1 | awk '{print $1 " is " $5 " Utilized Mounted on " $6 " with a Size of " $2 " has Used " $3 " Leaving only " $4 " of Available Space. "}'`"
This is the idea I had in my head I just don't know how to make it work. I know this is obviously syntactically incorrect but it makes more sense to me.
if [ "$rootuse" -gt "80" & less than "90"] then
echo $sev2_Warn
if [ "$rootuse" -gt "80" & -gt "90"] then
echo $sev1_Alarm
fi
fi
First, your if-statement needs an "else" to make it do only one action at most. And of course you want that one action to be the most severe, so check for gt 90 first:
if [ "$rootuse" -gt 90 ]
then
echo $root_msg | $sev1_Alarm
else
if [ "$rootuse" -gt 80 ]
then
echo $root_msg | $sev2_Warn
fi
fi
Also, = and != are for strings, and -gt -lt -eq etc are numeric tests, so I use 90 instead of "90".
And when you pull % full, your cut gets only 2 digits because you want to leave the %-sign behind. But when it hits 100, your code will pull only 10 instead of 100. I can suggest the following code instead, which pipes into only awk and avoids 2nd and 3rd pipe:
You wrote:
Maybe I don't understand the concept of your example. Can you explain the [1] [2] [3] in your example and how it correalates to the 80 & 90?
It's an example of having multiple statements - each has to be true for the "if (true) then command" to work. Like I wrote - I don't use bash and this was only an example - you can change it to use less than, equal, greater than... It was the && you needed for yours. Jimbo put you on the correct track.