I am trying to monitor filesystem space using a shell script. That script should refer a config file that has alert status constraint. The config file is as below
FileSYSTEM WARNING CRITICAL
/dev/sda5 80 90
/dev/sda3 50 70
/dev/sda2 60 75
/dev/sda1 75 80
tmpfs 70 75
So whenever I run a script it should compare df -Ph's used percentage with that config file and trigger a warning(or) critical mail accordingly.
The script which I tried is as below
#!/bin/ksh
HOST=`hostname`
DATE=`date`
LOGDIR=/home/oracle/files/logs
CONFIG_FILE=/home/oracle/files/template
FILESYSTEM=`mount -l | egrep -v 'root'| awk '{print $3}'`
for i in $FILESYSTEM
do
df -Ph $i > ($LOGDIR)\FS.log
sed -e '/Filesystem/d' -e 's/\%/ /g' ${LOGDIR}/FS.log > ${LOGDIR}/FS1.log
SPACEUSED=$(awk '{print $5}' ${LOGDIR}/FS1.log)
while read -r line
do
FS_TEMPLATE=`awk {'print $1'}`
if ($i == $FS_TEMPLATE)
then
WARNING_LIMIT=`awk {'print $3'}`
CRITICAL_LIMIT=`awk {'print $2'}`
if ($SPACEUSED == $CRITICAL_LIMIT)
then
echo ' mail criticality'
elseif ($SPACEUSED -ge $WARNING_LIMIT)
then
echo 'waning'
fi
fi
done < $CONFIG_FILE
done
# Remove temporary work files.
rm -f ${LOGDIR}/FS.log
rm -f ${LOGDIR}/FS1.log
# End of Script
But it is not working. How could I achieve it?