SlideShare a Scribd company logo
2
Most read
3
Most read
Bash Script To Generate Disk Usage Report and E-Mail
Overview
The purpose of this document is to generate HTML Disk usage report and email the report.
Applies To
CentOS 7, RHEL 7
Pre-requisites
 Bash
Shell Script Snippet
#!/bin/bash
#
# Environment Variables
#
TODAY="at $(date '+%H:%M on %d-%b-%y')"
OutputFilename=$(date +"%b_%d_%Y".html)
#
# Remove old HTML File
#
if [ -f /tmp/${OutputFilename} ]; then
rm -f /tmp/${OutputFilename}
fi
#
# Create HTML File with Table
#
(
echo '<HTML><HEAD><TITLE>Disk Usage Statistics</TITLE></HEAD>'
echo '<BODY>'
echo '<H3>Disk Usage Report for server - '$(uname -n)'</H3>'
echo '<P>Report Generated '${TODAY}'</P>'
echo '<TABLE BORDER=3 CELLSPACING=2 CELLPADDING=0>'
echo '<TR BGCOLOR="#5CE6E6"> <TH>Filesystem</TH> <TH>1024 blocks (Total)</TH> <TH>Disk
Used</TH> <TH>Available</TH> <TH>Percentage Info</TH> <TH>Mounted On</TH> <TH>Critical
Alert</TH></TR>'
Bash Script To Generate Disk Usage Report and E-Mail
#
# Collate Disk Usage Information
#
df -Pml |awk 'NR>1 && NF==6'|sort|while read FileSystem Size DiskUsed DiskFree DiskPercentUsed
MountPoint
do
PERCENT=${DiskPercentUsed%%%}
#
# Verify if disk usage is greater equal to, than set threshold limit - 90%
#
if [[ ${PERCENT} -ge 90 ]];
then
COLOR=red
CRITICALALERT="Yes, Notify"
#
# If the disk space used is greater than 70% and less than 80% set alert color as orange
#
elif [ ${PERCENT} -ge 70 ] && [ ${PERCENT} -le 80 ];
then
COLOR=orange
CRITICALALERT="No"
#
# Other usage percentage set color as green
#
else
COLOR=green
CRITICALALERT="NA"
fi
#
# Create Table Columns
#
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><TD>'$MountPoint'</TD>'
echo '<TD><FONT font-weight="bold">'$CRITICALALERT'</TD></FONT></TR>'
done
echo '</TABLE><P><FONT font-weight="bold">By IT Team</P><BODY></HTML>'
) | tee ${0##*/}.html
Bash Script To Generate Disk Usage Report and E-Mail
#
# Send E-Mail Notification – Snippet
#
(
echo From: SendersEMailAddress@domain.com
echo To: ReceiptsEMailAddress@domain.com
echo "Content-Type: text/html; "
echo Subject: Disk Usage Report for server `hostname`
echo
cat ${0##*/}.html
) | sendmail -t
A Sample HTML E-Mail
For the sake of demonstration, in this email notification, threshold was set as 30.

More Related Content

What's hot (20)

DOC
Oracle Audit vault
uzzal basak
 
PDF
MySQL 8.0.16 New Features Summary
Olivier DASINI
 
PDF
MySQL 8.0 EXPLAIN ANALYZE
Norvald Ryeng
 
PDF
PostgreSQL Deep Internal
EXEM
 
DOCX
Backup and Restore of database on 2-Node RAC
Paulo Fagundes
 
PPT
Linux presentation
Nikhil Jain
 
PPTX
Linux Run Level
Gaurav Mishra
 
PPT
Mysql
Rathan Raj
 
PDF
Apache Spark - Dataframes & Spark SQL - Part 1 | Big Data Hadoop Spark Tutori...
CloudxLab
 
PPTX
Apache Ranger Hive Metastore Security
DataWorks Summit/Hadoop Summit
 
PPTX
Optimizing Apache Spark SQL Joins
Databricks
 
DOC
Analyzing awr report
satish Gaddipati
 
PDF
Introduction VAUUM, Freezing, XID wraparound
Masahiko Sawada
 
PPT
Recovery of lost or corrupted inno db tables(mysql uc 2010)
Aleksandr Kuzminsky
 
PPTX
Exadata db node update
pat2001
 
PDF
Stored-Procedures-Presentation
Chuck Walker
 
PDF
100 COOL MAINFRAME TIPS
Nirmal Pati
 
PDF
Deep dive into PostgreSQL statistics.
Alexey Lesovsky
 
PDF
Tips on how to improve the performance of your custom modules for high volume...
Odoo
 
PPTX
Introduction Linux Device Drivers
NEEVEE Technologies
 
Oracle Audit vault
uzzal basak
 
MySQL 8.0.16 New Features Summary
Olivier DASINI
 
MySQL 8.0 EXPLAIN ANALYZE
Norvald Ryeng
 
PostgreSQL Deep Internal
EXEM
 
Backup and Restore of database on 2-Node RAC
Paulo Fagundes
 
Linux presentation
Nikhil Jain
 
Linux Run Level
Gaurav Mishra
 
Mysql
Rathan Raj
 
Apache Spark - Dataframes & Spark SQL - Part 1 | Big Data Hadoop Spark Tutori...
CloudxLab
 
Apache Ranger Hive Metastore Security
DataWorks Summit/Hadoop Summit
 
Optimizing Apache Spark SQL Joins
Databricks
 
Analyzing awr report
satish Gaddipati
 
Introduction VAUUM, Freezing, XID wraparound
Masahiko Sawada
 
Recovery of lost or corrupted inno db tables(mysql uc 2010)
Aleksandr Kuzminsky
 
Exadata db node update
pat2001
 
Stored-Procedures-Presentation
Chuck Walker
 
100 COOL MAINFRAME TIPS
Nirmal Pati
 
Deep dive into PostgreSQL statistics.
Alexey Lesovsky
 
Tips on how to improve the performance of your custom modules for high volume...
Odoo
 
Introduction Linux Device Drivers
NEEVEE Technologies
 

Viewers also liked (20)

PDF
Shell Script Disk Usage Report and E-Mail Current Threshold Status
VCP Muthukrishna
 
PDF
File Space Usage Information and EMail Report - Shell Script
VCP Muthukrishna
 
PDF
How To Audit Server Login and Shutdown or Reboot Activity
VCP Muthukrishna
 
PDF
How to Install and Configure AWS CLI on RHEL 7
VCP Muthukrishna
 
PDF
Installation CentOS 6.3
VCP Muthukrishna
 
PDF
DNF Failed To Open Cache
VCP Muthukrishna
 
PDF
How To Manage Yum Packages Interactive Shell
VCP Muthukrishna
 
PDF
Shell Script to Extract IP Address, MAC Address Information
VCP Muthukrishna
 
PDF
How To Create RDS Database for WordPress in AWS on RHEL 7 or CentOS 7
VCP Muthukrishna
 
PDF
How To Install OpenFire in CentOS 7
VCP Muthukrishna
 
PDF
Bash Script - How To Monitor Application Error Logs and Send Notification
VCP Muthukrishna
 
PDF
How To Install and Configure AWS CLI on RHEL 7
VCP Muthukrishna
 
PDF
How to Troubleshoot SELinux Audit2Allow unable to open (null)
VCP Muthukrishna
 
PDF
How To Manage Services on RHEL 7 or CentOS 7
VCP Muthukrishna
 
PDF
How To List YUM Packages
VCP Muthukrishna
 
PDF
How To Install and Configure Splunk on RHEL 7 in AWS
VCP Muthukrishna
 
PDF
How To Manage Yum History
VCP Muthukrishna
 
PDF
How To Manage Yum Packages - Group Packages
VCP Muthukrishna
 
PDF
How to Manage journalctl Logging System on RHEL 7
VCP Muthukrishna
 
PDF
How To Manage Yum Cache
VCP Muthukrishna
 
Shell Script Disk Usage Report and E-Mail Current Threshold Status
VCP Muthukrishna
 
File Space Usage Information and EMail Report - Shell Script
VCP Muthukrishna
 
How To Audit Server Login and Shutdown or Reboot Activity
VCP Muthukrishna
 
How to Install and Configure AWS CLI on RHEL 7
VCP Muthukrishna
 
Installation CentOS 6.3
VCP Muthukrishna
 
DNF Failed To Open Cache
VCP Muthukrishna
 
How To Manage Yum Packages Interactive Shell
VCP Muthukrishna
 
Shell Script to Extract IP Address, MAC Address Information
VCP Muthukrishna
 
How To Create RDS Database for WordPress in AWS on RHEL 7 or CentOS 7
VCP Muthukrishna
 
How To Install OpenFire in CentOS 7
VCP Muthukrishna
 
Bash Script - How To Monitor Application Error Logs and Send Notification
VCP Muthukrishna
 
How To Install and Configure AWS CLI on RHEL 7
VCP Muthukrishna
 
How to Troubleshoot SELinux Audit2Allow unable to open (null)
VCP Muthukrishna
 
How To Manage Services on RHEL 7 or CentOS 7
VCP Muthukrishna
 
How To List YUM Packages
VCP Muthukrishna
 
How To Install and Configure Splunk on RHEL 7 in AWS
VCP Muthukrishna
 
How To Manage Yum History
VCP Muthukrishna
 
How To Manage Yum Packages - Group Packages
VCP Muthukrishna
 
How to Manage journalctl Logging System on RHEL 7
VCP Muthukrishna
 
How To Manage Yum Cache
VCP Muthukrishna
 
Ad

More from VCP Muthukrishna (20)

PDF
How to Fix Duplicate Packages in YUM on CentOS 7
VCP Muthukrishna
 
PDF
How To Install and Configure GNome on CentOS 7
VCP Muthukrishna
 
PDF
How To Connect to Active Directory User Validation
VCP Muthukrishna
 
PDF
How To Connect To Active Directory PowerShell
VCP Muthukrishna
 
PDF
How To List Files on Remote Server - PowerShell
VCP Muthukrishna
 
PDF
How To List Files and Display In HTML Format
VCP Muthukrishna
 
PDF
How To Check and Delete a File via PowerShell
VCP Muthukrishna
 
PDF
Zimbra Troubleshooting - Mails not being Delivered or Deferred or Connection ...
VCP Muthukrishna
 
PDF
How To Setup SSH Keys on CentOS 7
VCP Muthukrishna
 
PDF
How To Install and Configure Open SSH Server on Ubuntu
VCP Muthukrishna
 
PDF
Windows PowerShell Basics - How To List PSDrive Info
VCP Muthukrishna
 
PDF
How To List Nginx Modules Installed / Complied on CentOS 7
VCP Muthukrishna
 
PDF
Windows PowerShell Basics – How To Create powershell for loop
VCP Muthukrishna
 
PDF
How To Construct IF and Else Conditional Statements
VCP Muthukrishna
 
PDF
How To Create PowerShell Function Mandatory Parameter and Optional Parameter
VCP Muthukrishna
 
PDF
How To Create Power Shell Function Mandatory Parameter Value
VCP Muthukrishna
 
PDF
How To Create PowerShell Function
VCP Muthukrishna
 
PDF
How To Disable IE Enhanced Security Windows PowerShell
VCP Muthukrishna
 
PDF
How To Check IE Enhanced Security Is Enabled Windows PowerShell
VCP Muthukrishna
 
PDF
How To Configure Nginx Load Balancer on CentOS 7
VCP Muthukrishna
 
How to Fix Duplicate Packages in YUM on CentOS 7
VCP Muthukrishna
 
How To Install and Configure GNome on CentOS 7
VCP Muthukrishna
 
How To Connect to Active Directory User Validation
VCP Muthukrishna
 
How To Connect To Active Directory PowerShell
VCP Muthukrishna
 
How To List Files on Remote Server - PowerShell
VCP Muthukrishna
 
How To List Files and Display In HTML Format
VCP Muthukrishna
 
How To Check and Delete a File via PowerShell
VCP Muthukrishna
 
Zimbra Troubleshooting - Mails not being Delivered or Deferred or Connection ...
VCP Muthukrishna
 
How To Setup SSH Keys on CentOS 7
VCP Muthukrishna
 
How To Install and Configure Open SSH Server on Ubuntu
VCP Muthukrishna
 
Windows PowerShell Basics - How To List PSDrive Info
VCP Muthukrishna
 
How To List Nginx Modules Installed / Complied on CentOS 7
VCP Muthukrishna
 
Windows PowerShell Basics – How To Create powershell for loop
VCP Muthukrishna
 
How To Construct IF and Else Conditional Statements
VCP Muthukrishna
 
How To Create PowerShell Function Mandatory Parameter and Optional Parameter
VCP Muthukrishna
 
How To Create Power Shell Function Mandatory Parameter Value
VCP Muthukrishna
 
How To Create PowerShell Function
VCP Muthukrishna
 
How To Disable IE Enhanced Security Windows PowerShell
VCP Muthukrishna
 
How To Check IE Enhanced Security Is Enabled Windows PowerShell
VCP Muthukrishna
 
How To Configure Nginx Load Balancer on CentOS 7
VCP Muthukrishna
 
Ad

Recently uploaded (20)

PDF
Automating Feature Enrichment and Station Creation in Natural Gas Utility Net...
Safe Software
 
PPTX
"Autonomy of LLM Agents: Current State and Future Prospects", Oles` Petriv
Fwdays
 
PDF
The 2025 InfraRed Report - Redpoint Ventures
Razin Mustafiz
 
PDF
Staying Human in a Machine- Accelerated World
Catalin Jora
 
PDF
Transcript: New from BookNet Canada for 2025: BNC BiblioShare - Tech Forum 2025
BookNet Canada
 
PPTX
OpenID AuthZEN - Analyst Briefing July 2025
David Brossard
 
PDF
Agentic AI lifecycle for Enterprise Hyper-Automation
Debmalya Biswas
 
PDF
POV_ Why Enterprises Need to Find Value in ZERO.pdf
darshakparmar
 
PDF
Transcript: Book industry state of the nation 2025 - Tech Forum 2025
BookNet Canada
 
PPTX
Future Tech Innovations 2025 – A TechLists Insight
TechLists
 
PPTX
COMPARISON OF RASTER ANALYSIS TOOLS OF QGIS AND ARCGIS
Sharanya Sarkar
 
PDF
Building Real-Time Digital Twins with IBM Maximo & ArcGIS Indoors
Safe Software
 
PDF
Bitcoin for Millennials podcast with Bram, Power Laws of Bitcoin
Stephen Perrenod
 
PDF
"Beyond English: Navigating the Challenges of Building a Ukrainian-language R...
Fwdays
 
PDF
Peak of Data & AI Encore AI-Enhanced Workflows for the Real World
Safe Software
 
PPTX
AUTOMATION AND ROBOTICS IN PHARMA INDUSTRY.pptx
sameeraaabegumm
 
PDF
Reverse Engineering of Security Products: Developing an Advanced Microsoft De...
nwbxhhcyjv
 
PPTX
Seamless Tech Experiences Showcasing Cross-Platform App Design.pptx
presentifyai
 
PPTX
Mastering ODC + Okta Configuration - Chennai OSUG
HathiMaryA
 
PDF
What’s my job again? Slides from Mark Simos talk at 2025 Tampa BSides
Mark Simos
 
Automating Feature Enrichment and Station Creation in Natural Gas Utility Net...
Safe Software
 
"Autonomy of LLM Agents: Current State and Future Prospects", Oles` Petriv
Fwdays
 
The 2025 InfraRed Report - Redpoint Ventures
Razin Mustafiz
 
Staying Human in a Machine- Accelerated World
Catalin Jora
 
Transcript: New from BookNet Canada for 2025: BNC BiblioShare - Tech Forum 2025
BookNet Canada
 
OpenID AuthZEN - Analyst Briefing July 2025
David Brossard
 
Agentic AI lifecycle for Enterprise Hyper-Automation
Debmalya Biswas
 
POV_ Why Enterprises Need to Find Value in ZERO.pdf
darshakparmar
 
Transcript: Book industry state of the nation 2025 - Tech Forum 2025
BookNet Canada
 
Future Tech Innovations 2025 – A TechLists Insight
TechLists
 
COMPARISON OF RASTER ANALYSIS TOOLS OF QGIS AND ARCGIS
Sharanya Sarkar
 
Building Real-Time Digital Twins with IBM Maximo & ArcGIS Indoors
Safe Software
 
Bitcoin for Millennials podcast with Bram, Power Laws of Bitcoin
Stephen Perrenod
 
"Beyond English: Navigating the Challenges of Building a Ukrainian-language R...
Fwdays
 
Peak of Data & AI Encore AI-Enhanced Workflows for the Real World
Safe Software
 
AUTOMATION AND ROBOTICS IN PHARMA INDUSTRY.pptx
sameeraaabegumm
 
Reverse Engineering of Security Products: Developing an Advanced Microsoft De...
nwbxhhcyjv
 
Seamless Tech Experiences Showcasing Cross-Platform App Design.pptx
presentifyai
 
Mastering ODC + Okta Configuration - Chennai OSUG
HathiMaryA
 
What’s my job again? Slides from Mark Simos talk at 2025 Tampa BSides
Mark Simos
 

Bash Script Disk Space Utilization Report and EMail

  • 1. Bash Script To Generate Disk Usage Report and E-Mail Overview The purpose of this document is to generate HTML Disk usage report and email the report. Applies To CentOS 7, RHEL 7 Pre-requisites  Bash Shell Script Snippet #!/bin/bash # # Environment Variables # TODAY="at $(date '+%H:%M on %d-%b-%y')" OutputFilename=$(date +"%b_%d_%Y".html) # # Remove old HTML File # if [ -f /tmp/${OutputFilename} ]; then rm -f /tmp/${OutputFilename} fi # # Create HTML File with Table # ( echo '<HTML><HEAD><TITLE>Disk Usage Statistics</TITLE></HEAD>' echo '<BODY>' echo '<H3>Disk Usage Report for server - '$(uname -n)'</H3>' echo '<P>Report Generated '${TODAY}'</P>' echo '<TABLE BORDER=3 CELLSPACING=2 CELLPADDING=0>' echo '<TR BGCOLOR="#5CE6E6"> <TH>Filesystem</TH> <TH>1024 blocks (Total)</TH> <TH>Disk Used</TH> <TH>Available</TH> <TH>Percentage Info</TH> <TH>Mounted On</TH> <TH>Critical Alert</TH></TR>'
  • 2. Bash Script To Generate Disk Usage Report and E-Mail # # Collate Disk Usage Information # df -Pml |awk 'NR>1 && NF==6'|sort|while read FileSystem Size DiskUsed DiskFree DiskPercentUsed MountPoint do PERCENT=${DiskPercentUsed%%%} # # Verify if disk usage is greater equal to, than set threshold limit - 90% # if [[ ${PERCENT} -ge 90 ]]; then COLOR=red CRITICALALERT="Yes, Notify" # # If the disk space used is greater than 70% and less than 80% set alert color as orange # elif [ ${PERCENT} -ge 70 ] && [ ${PERCENT} -le 80 ]; then COLOR=orange CRITICALALERT="No" # # Other usage percentage set color as green # else COLOR=green CRITICALALERT="NA" fi # # Create Table Columns # 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><TD>'$MountPoint'</TD>' echo '<TD><FONT font-weight="bold">'$CRITICALALERT'</TD></FONT></TR>' done echo '</TABLE><P><FONT font-weight="bold">By IT Team</P><BODY></HTML>' ) | tee ${0##*/}.html
  • 3. Bash Script To Generate Disk Usage Report and E-Mail # # Send E-Mail Notification – Snippet # ( echo From: [email protected] echo To: [email protected] echo "Content-Type: text/html; " echo Subject: Disk Usage Report for server `hostname` echo cat ${0##*/}.html ) | sendmail -t A Sample HTML E-Mail For the sake of demonstration, in this email notification, threshold was set as 30.