Embed presentation
Downloaded 25 times
![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>'](https://image.slidesharecdn.com/filespaceusagereportande-mail-151113070006-lva1-app6891/85/File-Space-Usage-Information-and-EMail-Report-Shell-Script-1-320.jpg)


This script generates an HTML report of the top 10 largest files and directories on a server by size and emails the report. It uses the du command to get disk usage information, sorts the results in descending order of size, and outputs the top 10 to a HTML table. The table is written to a file and emailed using sendmail to notify of disk space usage.
![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>'](https://image.slidesharecdn.com/filespaceusagereportande-mail-151113070006-lva1-app6891/85/File-Space-Usage-Information-and-EMail-Report-Shell-Script-1-320.jpg)
