SlideShare a Scribd company logo
Bash Script – File Space Usage Report and E-Mail
Overview
The purpose of this document is to generate HTML File Space usage information and email the report.
This script lists top 10 file space usage information.
Applies To
CentOS 7, RHEL 7
Pre-requisites
 Bash
 tee
Shell Script Snippet
#!/bin/bash
#
# Environment Variables
#
TODAY="at $(date '+%H:%M on %d-%b-%y')"
OutputFilename=$(date +"%b_%d_%Y".html)
SCAN_PATH=/
#
# Remove old HTML File
#
if [ -f /tmp/${OutputFilename} ]; then
rm -f /tmp/${OutputFilename}
fi
#
# Create Table Columns
#
(
echo '<HTML><HEAD><TITLE>Disk Utilization Report</TITLE></HEAD>'
echo '<BODY>'
echo '<H3>Disk Utilization 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> Filesize </TH> <TH> File Location </TH></TR>'
Bash Script – File Space Usage Report and E-Mail
#
# Collate Disk Size Usage of File and its location
# Read and assign values to variables
#
du ${SCAN_PATH} -Sh * 2>/dev/null | sort -rh | head -n 10 | while read DiskSpaceUsed FileLocation
do
echo '<TR><TD>'$DiskSpaceUsed'</TD><TD>'$FileLocation'</TD></TR>'
done
echo '</TABLE><P>'
echo 'Report generated by IT Admin Team</P></BODY></HTML>'
) | tee ${0##*/}.html
#
# 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

More Related Content

PDF
Shell Script to Extract IP Address, MAC Address Information
PPTX
Commit2015 kharchenko - python generators - ext
PPTX
2015 555 kharchenko_ppt
PDF
KubeCon EU 2016: Custom Volume Plugins
DOCX
serverstats
PDF
Hive practice
PDF
Ethiopian multiplication in Perl6
PPTX
Process monitoring in UNIX shell scripting
Shell Script to Extract IP Address, MAC Address Information
Commit2015 kharchenko - python generators - ext
2015 555 kharchenko_ppt
KubeCon EU 2016: Custom Volume Plugins
serverstats
Hive practice
Ethiopian multiplication in Perl6
Process monitoring in UNIX shell scripting

What's hot (20)

PPT
Hands on Hadoop
PDF
Workshop on command line tools - day 2
PDF
Workshop on command line tools - day 1
PPTX
Cis 216 – shell scripting
PDF
Git Tutorial Yang Yang
PPTX
CouchDB Day NYC 2017: Full Text Search
PDF
PDF
PuppetDB, Puppet Explorer and puppetdbquery
PDF
Redis as a message queue
PPT
Perl 1997 Perl As A System Glue
PDF
Try PostgreSQL on linux
PDF
Routing @ Scuk.cz
PPT
Unix 5 en
PDF
Installing Apache Hive, internal and external table, import-export
KEY
Tres Gemas De Ruby
PPTX
Linux Shell Scripts and Shell Commands✌️
PDF
Unix cheatsheet
PPTX
Pig workshop
PDF
Tablespaces
Hands on Hadoop
Workshop on command line tools - day 2
Workshop on command line tools - day 1
Cis 216 – shell scripting
Git Tutorial Yang Yang
CouchDB Day NYC 2017: Full Text Search
PuppetDB, Puppet Explorer and puppetdbquery
Redis as a message queue
Perl 1997 Perl As A System Glue
Try PostgreSQL on linux
Routing @ Scuk.cz
Unix 5 en
Installing Apache Hive, internal and external table, import-export
Tres Gemas De Ruby
Linux Shell Scripts and Shell Commands✌️
Unix cheatsheet
Pig workshop
Tablespaces
Ad

Viewers also liked (20)

PDF
How to Install Configure and Use sysstat utils on RHEL 7
PDF
Bash Script Disk Space Utilization Report and EMail
PDF
Installation CentOS 6.3
PDF
How To Audit Server Login and Shutdown or Reboot Activity
PDF
DNF Failed To Open Cache
PDF
How to Install and Configure AWS CLI on RHEL 7
PDF
How To Manage Yum Packages Interactive Shell
PDF
How To Create RDS Database for WordPress in AWS on RHEL 7 or CentOS 7
PDF
How To Install OpenFire in CentOS 7
PDF
How to Troubleshoot SELinux Audit2Allow unable to open (null)
PDF
Bash Script - How To Monitor Application Error Logs and Send Notification
PDF
How To Install and Configure AWS CLI on RHEL 7
PDF
How To Manage Yum Repositories
PDF
How To Install and Configure Splunk on RHEL 7 in AWS
PDF
How to Manage journalctl Logging System on RHEL 7
PDF
How To Manage Yum Packages - Group Packages
PDF
How To Manage Services on RHEL 7 or CentOS 7
PDF
How To Manage Yum Cache
PDF
How To Manage Yum History
PDF
How To List YUM Packages
How to Install Configure and Use sysstat utils on RHEL 7
Bash Script Disk Space Utilization Report and EMail
Installation CentOS 6.3
How To Audit Server Login and Shutdown or Reboot Activity
DNF Failed To Open Cache
How to Install and Configure AWS CLI on RHEL 7
How To Manage Yum Packages Interactive Shell
How To Create RDS Database for WordPress in AWS on RHEL 7 or CentOS 7
How To Install OpenFire in CentOS 7
How to Troubleshoot SELinux Audit2Allow unable to open (null)
Bash Script - How To Monitor Application Error Logs and Send Notification
How To Install and Configure AWS CLI on RHEL 7
How To Manage Yum Repositories
How To Install and Configure Splunk on RHEL 7 in AWS
How to Manage journalctl Logging System on RHEL 7
How To Manage Yum Packages - Group Packages
How To Manage Services on RHEL 7 or CentOS 7
How To Manage Yum Cache
How To Manage Yum History
How To List YUM Packages
Ad

More from VCP Muthukrishna (20)

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

Recently uploaded (20)

PPTX
20250228 LYD VKU AI Blended-Learning.pptx
PPTX
Cloud computing and distributed systems.
PDF
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
PDF
CIFDAQ's Market Insight: SEC Turns Pro Crypto
PDF
NewMind AI Weekly Chronicles - August'25 Week I
PDF
Chapter 3 Spatial Domain Image Processing.pdf
PDF
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
PPTX
Digital-Transformation-Roadmap-for-Companies.pptx
PDF
Building Integrated photovoltaic BIPV_UPV.pdf
PDF
Review of recent advances in non-invasive hemoglobin estimation
PDF
Encapsulation_ Review paper, used for researhc scholars
PDF
Network Security Unit 5.pdf for BCA BBA.
PDF
Diabetes mellitus diagnosis method based random forest with bat algorithm
PDF
NewMind AI Monthly Chronicles - July 2025
PDF
Mobile App Security Testing_ A Comprehensive Guide.pdf
PDF
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
PDF
Empathic Computing: Creating Shared Understanding
PDF
The Rise and Fall of 3GPP – Time for a Sabbatical?
PPT
Teaching material agriculture food technology
PPTX
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
20250228 LYD VKU AI Blended-Learning.pptx
Cloud computing and distributed systems.
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
CIFDAQ's Market Insight: SEC Turns Pro Crypto
NewMind AI Weekly Chronicles - August'25 Week I
Chapter 3 Spatial Domain Image Processing.pdf
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
Digital-Transformation-Roadmap-for-Companies.pptx
Building Integrated photovoltaic BIPV_UPV.pdf
Review of recent advances in non-invasive hemoglobin estimation
Encapsulation_ Review paper, used for researhc scholars
Network Security Unit 5.pdf for BCA BBA.
Diabetes mellitus diagnosis method based random forest with bat algorithm
NewMind AI Monthly Chronicles - July 2025
Mobile App Security Testing_ A Comprehensive Guide.pdf
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
Empathic Computing: Creating Shared Understanding
The Rise and Fall of 3GPP – Time for a Sabbatical?
Teaching material agriculture food technology
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy

File Space Usage Information and EMail Report - Shell Script

  • 1. Bash Script – File Space Usage Report and E-Mail Overview The purpose of this document is to generate HTML File Space usage information and email the report. This script lists top 10 file space usage information. Applies To CentOS 7, RHEL 7 Pre-requisites  Bash  tee Shell Script Snippet #!/bin/bash # # Environment Variables # TODAY="at $(date '+%H:%M on %d-%b-%y')" OutputFilename=$(date +"%b_%d_%Y".html) SCAN_PATH=/ # # Remove old HTML File # if [ -f /tmp/${OutputFilename} ]; then rm -f /tmp/${OutputFilename} fi # # Create Table Columns # ( echo '<HTML><HEAD><TITLE>Disk Utilization Report</TITLE></HEAD>' echo '<BODY>' echo '<H3>Disk Utilization 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> Filesize </TH> <TH> File Location </TH></TR>'
  • 2. Bash Script – File Space Usage Report and E-Mail # # Collate Disk Size Usage of File and its location # Read and assign values to variables # du ${SCAN_PATH} -Sh * 2>/dev/null | sort -rh | head -n 10 | while read DiskSpaceUsed FileLocation do echo '<TR><TD>'$DiskSpaceUsed'</TD><TD>'$FileLocation'</TD></TR>' done echo '</TABLE><P>' echo 'Report generated by IT Admin Team</P></BODY></HTML>' ) | tee ${0##*/}.html # # 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