UNIX cluster disk usage report generation for yesterday & today and email


 
Thread Tools Search this Thread
Top Forums UNIX for Beginners Questions & Answers UNIX cluster disk usage report generation for yesterday & today and email
# 1  
Old 04-12-2019
UNIX cluster disk usage report generation for yesterday & today and email

HI Team,

I am trying to create a shell script to generate a yesterday and today report to compare and email in daily basis. can you please help me on the same.
Code:
#!/bin/bash
#Author: *******************
#Description:  This script will return the following set of system information:

EMAIL='*************'
function sysstat {
echo -e "
********************************************************************
    Health Check Report (CPU,Process,Disk Usage, Memory)
********************************************************************


Hostname         : `hostname`
Kernel Version   : `uname -r`
Uptime           : `uptime | sed 's/.*up \([^,]*\), .*/\1/'`
Last Reboot Time : `who -b | awk '{print $3,$4}'`
Cluster Utilization:
`df -h /path`


********************************************************************
CPU Load - >
*********************************************************************
"
MPSTAT=`which mpstat`
MPSTAT=$?
if [ $MPSTAT != 0 ]
then
        echo "NIL"
else
echo -e ""
LSCPU=`which lscpu`
LSCPU=$?
if [ $LSCPU != 0 ]
then
        RESULT=$RESULT" lscpu required to producre acqurate reults"
else
cpus=`lscpu | grep -e "^CPU(s):" | cut -f2 -d: | awk '{print $1}'`
i=0
while [ $i -lt $cpus ]
do
        echo "CPU$i : `mpstat -P ALL | awk -v var=$i '{ if ($3 == var ) print $4 }' `"
        let i=$i+1
done
fi
echo -e "
Load Average   : `uptime | awk -F'load average:' '{ print $2 }' | cut -f1 -d,`

Health Status : `uptime | awk -F'load average:' '{ print $2 }' | cut -f1 -d, | awk '{if ($1 > 2) print "Unhealthy"; else if ($1 > 1) print "Caution"; else print "Normal"}'`
"
fi
echo -e "
*********************************************************************
                             Process
*********************************************************************

=> Top memory using processs/application

PID %MEM RSS COMMAND
`ps aux | awk '{print $2, $4, $6, $11}' | sort -k3rn | head -n 10`

=> Top CPU using process/application
`top b -n1 | head -17 | tail -11`

*********************************************************************
Disk Usage - > Threshold < 70 Normal > 75% Caution > 80% Unhealthy
*********************************************************************
"
df -Pkh | grep -v 'Filesystem' > /tmp/df.status
while read DISK
do
        LINE=`echo $DISK | awk '{print $1,"\t",$6,"\t",$5," used","\t",$4," free space"}'`
        echo -e $LINE
        echo
done < /tmp/df.status
echo -e "

Health Status"
echo
while read DISK
do
        USAGE=`echo $DISK | awk '{print $5}' | cut -f1 -d%`
        if [ $USAGE -ge 95 ]
USAGE=`echo $DISK | awk '{print $5}' | cut -f1 -d%`
        if [ $USAGE -ge 95 ]
        then
                STATUS='Unhealty'
        elif [ $USAGE -ge 90 ]
        then
                STATUS='Caution'
        else
                STATUS='Normal'
        fi

        LINE=`echo $DISK | awk '{print $1,"\t",$6}'`
        echo -ne $LINE "\t\t" $STATUS
        echo
done < /tmp/df.status
rm /tmp/df.status
TOTALMEM=`free -m | head -2 | tail -1| awk '{print $2}'`
TOTALBC=`echo "scale=2;if($TOTALMEM<1024 && $TOTALMEM > 0) print 0;$TOTALMEM/1024"| bc -l`
USEDMEM=`free -m | head -2 | tail -1| awk '{print $3}'`
USEDBC=`echo "scale=2;if($USEDMEM<1024 && $USEDMEM > 0) print 0;$USEDMEM/1024"|bc -l`
FREEMEM=`free -m | head -2 | tail -1| awk '{print $4}'`
FREEBC=`echo "scale=2;if($FREEMEM<1024 && $FREEMEM > 0) print 0;$FREEMEM/1024"|bc -l`
TOTALSWAP=`free -m | tail -1| awk '{print $2}'`
TOTALSBC=`echo "scale=2;if($TOTALSWAP<1024 && $TOTALSWAP > 0) print 0;$TOTALSWAP/1024"| bc -l`
USEDSWAP=`free -m | tail -1| awk '{print $3}'`
USEDSBC=`echo "scale=2;if($USEDSWAP<1024 && $USEDSWAP > 0) print 0;$USEDSWAP/1024"|bc -l`
FREESWAP=`free -m |  tail -1| awk '{print $4}'`
FREESBC=`echo "scale=2;if($FREESWAP<1024 && $FREESWAP > 0) print 0;$FREESWAP/1024"|bc -l`

echo -e "
*********************************************************************
                     Memory
*********************************************************************

=> Physical Memory

Total\tUsed\tFree\t%Free

${TOTALBC}GB\t${USEDBC}GB \t${FREEBC}GB\t$(($FREEMEM * 100 / $TOTALMEM  ))%

=> Swap Memory

Total\tUsed\tFree\t%Free
                                                              

${TOTALSBC}GB\t${USEDSBC}GB\t${FREESBC}GB\t$(($FREESWAP * 100 / $TOTALSWAP  ))%
"
}
FILENAME="health-`hostname`-`date +%m%d%y`-`date +%H%M`.txt"
sysstat > $FILENAME
echo -e "Reported file $FILENAME generated in current directory." $RESULT
if [ "$EMAIL" != '' ]
then
        STATUS=`which mail`
        if [ "$?" != 0 ]
        then
                echo "The program 'mail' is currently not installed."
        else
                cat $FILENAME | mail -s "$FILENAME" $EMAIL
        fi

Moderator's Comments:
Mod Comment Please do wrap your samples/codesin CODE TAGS as per forums rules.

Last edited by RavinderSingh13; 04-12-2019 at 04:10 PM..
# 2  
Old 04-12-2019
What is your question?
# 3  
Old 04-12-2019
UNIX cluster disk usage report generation for yesterday & today and email

Thanks for your reply, i am trying to change the above script to create yesterday report and today today report in two table format for comparison of my cluster utilization in daily basis. just wanted to see in a day how much data is getting increased everyday.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Generate disk space usage email alert

hi all members I have a shell script to generate disk space usage email alert if threshold is more than 80 %, now the requirement changed to keep sending alert emails for every 5% incremental usage ........ Any help would be greatly appreciated. ex - 80% , 85% ,90%,95%,100% we should get an... (6 Replies)
Discussion started by: anil529
6 Replies

2. Shell Programming and Scripting

Send Disk Space Usage Status via email

Hi Guys, Is there any way I can write a script that sends DISK SPACE USAGE STATUS via email once a week? Thanks, (5 Replies)
Discussion started by: g4v1n
5 Replies

3. Shell Programming and Scripting

Disk report generation problem

Hello everyone, I have a list of inputs as below. My logic is to get the particular powerdisk which matches for ASM disk which means take the major & minor number of each asm disk and matches with powerdisk info then get the particular powerdisk $ ls -l /dev/asm_* ---> ASM disk info... (11 Replies)
Discussion started by: kannan84
11 Replies

4. Shell Programming and Scripting

Unix - Disk usage command

Hi, I need a command that gives me the user who is using more space in the unix box (1 Reply)
Discussion started by: abinaya
1 Replies

5. UNIX for Dummies Questions & Answers

email warning script for disk usage

I'm trying to monitor disk usage, using cron to run a script to email me when disk capacity exceeds 66%. When I use df (actually, "df -k" because I find the format useful), disk capacity shows as field 5. However, that field includes a % which is confusing my ">" comparison to include a warning. ... (3 Replies)
Discussion started by: InvisibleMan
3 Replies

6. AIX

errpt with param for yesterday and today

Hi All, I would like to create a script with "errpt" that will read the date yesterday and today and execute this: "errpt -a -s yesterdaydatetime -e todaydatetime". For example: >errpt -a -s 0604000008 -s 0605235908 Note: Time is fixed with start "0000" and end "2359". So... (0 Replies)
Discussion started by: itik
0 Replies

7. UNIX for Dummies Questions & Answers

Uncertainty on disk usage report

Hi all, My system is running on RHEL4. I've just deleted 2 huge tablespaces from Oracle. Then I saw the disk usage. The report by df differs from the du. Do you know why they shows different results? Which one is correct? # df -h Filesystem Size Used Avail Use% Mounted... (1 Reply)
Discussion started by: mr_bold
1 Replies

8. Shell Programming and Scripting

Disk Usage in Unix

Hi, Please let me know how do we write a piece of code to find the disk usage in UNIX (3 Replies)
Discussion started by: Shilpi
3 Replies

9. Shell Programming and Scripting

Need to send email on HIGH Disk usage

Hi Guys I am looking for a python / PERL script which will send me email when ever my disk becomes more than 90% full. By the way my OS is Win XP. If anybody have already has written same type of script or something very similar kind of script, that will also be very helpful. Thanks... (1 Reply)
Discussion started by: csaha
1 Replies

10. Shell Programming and Scripting

How do l test for carriage return & Disk space usage

Hi, I have just written a script in /bin/bash, however, l want to test if character is a carriage return or space. Also l want my script to be able to detect my disk space and send a mail if usage is more than 90% or send an alert. Thanks Kayode (6 Replies)
Discussion started by: kayode
6 Replies
Login or Register to Ask a Question