I building a script to check disk usage and send an email in case the amount is higher the threshold.
i have the thresolds store in a file config.sh:
disk /apps/home 65% 5%
and then i compared the value in the file with the current value and if higher send an email:
email_val=0
email_HTML="<html><body><table><tr><th>Mountpoint</th><th>Current Value</th><th>Threshold Value</th></tr>"
grep -hr "disk " config.sh | grep -v "^[[:space:]]*#"| while read diskOutput
do
echo "Found path: $diskOutput"
diskpath=`echo $diskOutput | awk '{print $2}'`
HighThreshold=`echo $diskOutput | awk '{print $3}' | cut -d'%' -f1`
LowThreshold=`echo $diskOutput | awk '{print $4}' | cut -d'%' -f1`
CurrentValue=`df $diskpath |grep -v "Use%"|grep -v "%iused" | grep -o "[0-9]*%" | cut -d'%' -f1`
if [ $CurrentValue -ge $HighThreshold ];
then
echo " sendTrapForHighDiskUsage: mount-$diskpath $HighThreshold $LowThreshold $CurrentValue"
email_val=1
email_HTML+=" <tr><td>$diskpath</td><td>$CurrentValue</td><td style=\"color:red\">$HighThreshold</td></tr>"
echo "High $email_HTML"
else
email_HTML+=" <tr><td>$diskpath</td><td>$CurrentValue</td><td>$HighThreshold</td></tr>"
echo "Normal $email_HTML"
fi
done
echo "end $email_HTML"
the problem here is that the values store in the variable email_HTML are not being kept when the while finish.
the output is only the below, even though i can see the echo with the correct value.
The end output:
<html><body><table><tr><th>Mountpoint</th><th>Current Value</th><th>Threshold Value</th></tr>
the supposed output:
<html><body><table><tr><th>Mountpoint</th><th>Current Value</th><th>Threshold Value</th></tr>
<tr><td>/apps/home</td><td>5</td><td>65</td></tr>
Thanks in advance, Macieira