Disk usage monitoring and record the disk used in last 24 hour


 
Thread Tools Search this Thread
Top Forums UNIX for Beginners Questions & Answers Disk usage monitoring and record the disk used in last 24 hour
# 1  
Old 04-22-2019
Disk usage monitoring and record the disk used in last 24 hour

HI I am Trying to edit the below code to send email every day with difference of disk utilized in for last 24 hours but instead getting same usage everyday. can you please help me to point out where my calculation is going wrong. Thank you.

=================
Code:
#!/bin/bash


TODAY="at $(date '+%H:%M on %d-%b-%y')"
OutputFilename=$(date +"%b_%d_%Y".html)
LastReport=/tmp/YesReport.txt
NowReport=/tmp/TodReport.txt
CurDate=`date +%D\ %T\ %Z`

CriticalPercentage=80
WarningPercentage=70
NormalPercentage=68

IPADDRESS=`hostname`

if [ -f /tmp/${OutputFilename} ]; then
 rm -f /tmp/${OutputFilename}
fi

if [ -f ${TodReport} ]; then
     mv ${TodReport} ${YesReport}
         cp /dev/null ${TodReport}
fi


df -Ph | grep -vE "^Filesystem|tmpfs|cdrom" | awk 'NR>0 && NF==6' | awk '{print $3}' > ${TodReport}
if [ -f ${YesReport} ]; then
 DiffValue=(`awk '{ getline getdifference < "/tmp/YesReport.txt"; $1 -= getdifference; print }' /tmp/TodReport.txt`)
fi

(
 echo '<HTML><HEAD><TITLE>Disk Usage Statistics</TITLE></HEAD>'
 echo '<BODY>'
 echo '<H3><font color="#5555E7" face="verdana" size="3">Disk Usage Report for server - '$(uname -n) DEV ${IPADDRESS}'</font></H3>'
 echo '<P style="color:#5555E7" face="verdana" size="3">Report Generated '${TODAY}'</P>'
 echo '<TABLE BORDER=1 CELLSPACING=0 CELLPADDING=2 bordercolor=#DEDEE2>'
echo '<P style="color:#5555E7" face="verdana" size="3">Report Generated '${TODAY}'</P>'
 echo '<TABLE BORDER=1 CELLSPACING=0 CELLPADDING=2 bordercolor=#DEDEE2>'
 echo '<style>
 body {
     font-family: verdana;
         font: 16px verdana, sans-serif;
}
tbody th { text-align:right; background: #F8F8FA; color:red}
</style>'
# echo '<TR BGCOLOR=\"#BBFFFF\"> <TH><font color="#5555E7"><font face="verdana"><b>Filesystem</b></font></TH> <TH>Total</TH> <TH>Disk Used</TH>
#<TH>Available</TH> <TH>Percentage Info</TH> <TH>Mounted On</TH> <TH>Critical Alert</TH>
#<TH>Report Date</TH> <TH>12 Hrs Difference </TH><//TR>'
echo '<TR BGCOLOR=\"#4863A0\"> <TH><font color="#5555E7" face="verdana" size="2"><b>Filesystem</b></font></TH> <TH><font color="#5555E7" face="verdana" size="2"><b>Total</b></font></TH> <TH><font color="#5555E7" face="verdana" size="2"><b>Disk Used</b></font></TH><TH><font color="#5555E7" size="2" face="verdana">
<b>Available</b></font></TH> <TH><font color="#5555E7" size="2" face="verdana"><b>Percentage Info</b></font></TH> <TH><font color="#5555E7" size="2" face="verdana">
<b>Mounted On</b></font></TH> <TH><font color="#5555E7" size="2" face="verdana"><b>Critical Alert</b></font></TH> <TH><font color="#5555E7" size="2" face="verdana">
<b>Report Date</b></font></TH> <TH><font color="#5555E7" size="2" face="verdana"><b>24 Hrs Difference</b></font></TH></TR>'




ArryCount=0
df -Ph | grep -vE "^Filesystem|tmpfs|cdrom" | awk 'NR>0 && NF==6'|sort|while read FileSystem Size DiskUsed DiskFree DiskPercentUsed MountPoint
 do
 PERCENT=${DiskPercentUsed%%%}


 TDiffValue=(`awk '{ getline getdifference < "/tmp/YesReport.txt"; $1 -= getdifference; print }' /tmp/TodReport.txt`)


 if [[ ${PERCENT} -ge ${CriticalPercentage} ]];
 then
 COLOR=red
 CRITICALALERT="Yes, Notify"
 elif [ ${PERCENT} -ge ${WarningPercentage} ] && [ ${PERCENT} -le 90 ];
 then
 COLOR=orange
 CRITICALALERT=No
 else
 COLOR=green
 CRITICALALERT=NA
 fi
CRITICALALERT=NA
 fi
 echo '<TR><TD>'$FileSystem'</TD><TD ALIGN=RIGHT>'$Size'</TD>'
 echo '<TD ALIGN=RIGHT>'$DiskUsed'</TD><TD ALIGN=RIGHT>'$DiskFree'</TD>'
 echo '<TD><TABLE BORDER=0 CELLSPACING=3 CELLPADDING=0>'
 echo '<TR><TD WIDTH='$((2 * $PERCENT))' BGCOLOR="'$COLOR'"></TD>'
 echo '<TD WIDTH='$((2 * (100 - $PERCENT)))' BGCOLOR="gray"></TD>'
 echo '<TD><FONT FONT-WEIGHT="bold" SIZE=-1
COLOR="'$COLOR'">'$DiskPercentUsed'</FONT></TD>'
 echo '<TR></TABLE><TD>'$MountPoint'</TD>'
 echo '<TD><FONT font-weight="bold">'$CRITICALALERT'</TD></FONT>'
 echo '<TD><FONT font-weight="bold">'`date`'</TD></FONT>'
 echo '<TD><FONT font-weight="bold">'${TDiffValue[ArryCount]} \(in bytes\)'</TD></FONT></TR>'
 echo $DiskUsed >> `hostname`.usage.txt
 ArryCount=$ArryCount+1
 done
 echo '</TABLE>'
 echo '</P><BR>'
 echo '<TABLE BORDER=1 CELLSPACING=3 CELLPADDING=0>'
 echo '<TR><TH FONT font-weight="bold">Legend Information</TH></TR>'
 echo '<TR><TD FONT color="white" BGCOLOR="RED">Critical Alert</TD></TR>'
 echo '<TR><TD FONT color="white" BGCOLOR="ORANGE">Warning Alert</TD></TR>'
 echo '<TR><TD FONT color="white" BGCOLOR="GREEN">No Action Alert</TD></TR>'
 echo '</TABLE>'
 echo '<BODY></HTML>'
 echo '<P><FONT font-weight="bold">Report Generated by MGT Big Data Admin Team</P>'
) | tee `hostname`_${0##*/}.html

Moderator's Comments:
Mod Comment Please use code tags
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Disk Usage

Hi, I have always felt problems using commands to check disk usage, or I should say I might not be using the commands properly. dfspace and free are 2 most frequent command that I use, but the data that it echoes is not comprehandable atleast to me.:wall::wall::wall::wall::wall: I want... (4 Replies)
Discussion started by: TH3M0Nk
4 Replies

2. Shell Programming and Scripting

Script for monitoring disk failures

Hi , Does anyone have a script for monitoring disk failures on a Solaris 10/11 box? Need one today ASAP, thnks in advance. (2 Replies)
Discussion started by: walnutpony123
2 Replies

3. Shell Programming and Scripting

Disk Space Monitoring Script - OLD and NEW

It's the old thread "Disk Space Monitoring Script", modified for UNIX This is the new code: df -k | awk ' { if ( int($4) > 90) {subject = $1 " More than 90% disk usage. Used: " $4 email = "email@test.com" print subject cmd = "mailx -s \"" subject "\" " email cmd | getline... (4 Replies)
Discussion started by: dungureanu
4 Replies

4. UNIX for Dummies Questions & Answers

Solaris Disk Monitoring?

Hi Guys, I'm looking for a way to monitor disk health/status for a Solaris 5.8 sparc machine. I'm looking for something similar to LSIutility or MegaCLI. Any suggestions? Output of `modinfo`: 30 102616fb 10be8 118 1 ssd (SCSI SSA/FCAL Disk Driver 1.151) 122 7821c000 18550 32 1 ... (2 Replies)
Discussion started by: tank126
2 Replies

5. Solaris

current CPU usage, memory usage, disk I/O oid(snmp)

Hi, I want to monitor the current cpu usage, monitor usage , disk I/o and network utlization for solaris using SNMP. I want the oids for above tasks. can you please tell me that Thank you (2 Replies)
Discussion started by: S_venkatesh
2 Replies

6. Filesystems, Disks and Memory

disk and memory monitoring problem

Hi all, I am looking for api to get me system monitoring statictics every 5 minutes. I am looking at the following statistics: 1. System CPU Usage 2. Process CPU Usage 3. Process Memory Usage 4. I/O Usage for a certain disk. 5. Process I/O bytes/sec utilization. I have seen very... (2 Replies)
Discussion started by: uiqbal
2 Replies

7. Shell Programming and Scripting

Disk Space Monitoring Script

#!/bin/bash # Disk Space Monitoring for more than 95 % # and Sending Alerts by Mail if ; then `df -k |awk '$5 > 95 {print $1 " ----------- " $5}' |mailx -s "More than 95% disk usage in DEV" email@test.com'; else exit 0 fi I get the... (8 Replies)
Discussion started by: sriram003
8 Replies

8. Shell Programming and Scripting

Disk Usage

Hi, I want to retrieve the directory in the shell script that is using maximum space on the disk.I was using du command but it displays all the directories that are using the space on the disk.How can retrieve the only directory which uses the maximum space on the disk?? Thanks in advance. ... (4 Replies)
Discussion started by: harikamamidala
4 Replies

9. UNIX for Dummies Questions & Answers

disk usage

how to i find out the disk usage on a server. say in windows examples its like C:/ D:/ and checking out the disk space. how can i find in Unix. can i just use df -k or should i go to each volume group and find that way. plz respond (2 Replies)
Discussion started by: karthikosu
2 Replies

10. UNIX for Dummies Questions & Answers

Disk Usage

Im using solaris 8 on a Sunfire 280r. Is there a command to show you how much disk space is being used in gigabytes or megabytes. I dont think theres an option for this using the df command. not for solaris anyway. thanks (3 Replies)
Discussion started by: lewisoco
3 Replies
Login or Register to Ask a Question