Shell Scripts

[Shell Script] – Monitor File system usage (HTML format email alert)

#!/bin/ksh
####################################################################
#       Script Name     :       Check_fs_alert.ksh
#       Date            :       30/08/2019
#       Description     :       This script checks for Filesysetm Space Usage
#       By		:	Kishore Uppala
####################################################################
echo "<html>" >/tmp/fs.html
echo "<head>" >>/tmp/fs.html
echo "</head>" >>/tmp/fs.html
echo "<body style='font-family: cambria;align: left;'>" >>/tmp/fs.html
echo "<h2 color='Black' align='center'><b>Issue: Mount Point running out of space</h2>" >>/tmp/fs.html
echo "<h3 color='green' align='left'style='font-family: cambria;'> Solution: Clear unused files (OR) Raise request to Unix team to add space</h3>" >>/tmp/fs.html
echo "<div align='left'><table border='1' align='left' style='font-family: cambria;' cellpadding='3'>" >>/tmp/fs.html
echo "<tr align='center'>" >>/tmp/fs.html
echo "<th> Filesystem </th>"  >>/tmp/fs.html
echo "<th> Total Space </th>"    >>/tmp/fs.html
echo "<th> Used </th>"  >>/tmp/fs.html
echo "<th> Available </th>" >>/tmp/fs.html
echo "<th> Capacity Used </th>" >>/tmp/fs.html
echo "<th> Mount Point </th>"   >>/tmp/fs.html
echo "</tr>" >>/tmp/fs.html
export MailId=Your_Email_Id@gmail.com
df -Ph | grep -v Filesystem | grep -v proc | sed 's/%//g' | while read FS TOTAL USED AVAIL CAP MOUNT
do

if [ $CAP -ge 80 ]
then
   echo "<tr align='center'>" >>/tmp/fs.html
   echo "<TD> $FS </TD>" >> /tmp/fs.html
   echo "<TD> $TOTAL </TD>" >> /tmp/fs.html
   echo "<TD> $USED </TD>" >> /tmp/fs.html
   echo "<TD> $AVAIL </TD>" >> /tmp/fs.html
   echo "<TD BGCOLOR='RED' style='font-weight:bold;'><div class='blink'>$CAP % </blink></TD>" >> /tmp/fs.html
   echo "<TD BGCOLOR='RED'>$MOUNT </TD>" >> /tmp/fs.html
   echo "</tr>" >> /tmp/fs.html

elif [ $CAP -ge 60 ]
    then
    echo "<tr align='center'>" >>/tmp/fs.html
    echo "<TD> $FS </TD>" >> /tmp/fs.html
    echo "<TD> $TOTAL </TD>" >> /tmp/fs.html
    echo "<TD> $USED </TD>" >> /tmp/fs.html
    echo "<TD> $AVAIL </TD>" >> /tmp/fs.html
    echo "<TD BGCOLOR='ORANGE' style='font-weight:bold;'>$CAP % </TD>" >> /tmp/fs.html
    echo "<TD BGCOLOR='ORANGE'>$MOUNT </TD>" >> /tmp/fs.html
    echo "</tr>" >> /tmp/fs.html
fi
done
echo "</table></div>" >>/tmp/fs.html
echo "</body>" >>/tmp/fs.html
echo "</html>"  >>/tmp/fs.html
c=`wc -l </tmp/fs.html`
if [ -f /tmp/fs.html ] && [ $c -gt 18 ] #Modify number 18 if you change any(intial) 18 lines for <table> and <th>
then
(export CONTENT="/tmp/fs.html"
export SUBJECT="[WARNING] - Alert: Disk space usage on `hostname` reached threshold level. Please check and take appropriate action"
echo "TO :$MailId"
echo "Subject: $SUBJECT"
echo "MIME-Version: 1.0"
echo "Content-Type: text/html"
echo "Content-Disposition: inline"
cat $CONTENT ) | /usr/lib/sendmail -r 'Oracle-DBA' $MailId
fi

Review
4
Comments Rating 0 (0 reviews)

About the author

BestTechReads

Add Comment

Click here to post a comment

Sending

Categories

Categories