Question & Answer
Question
How do I set a host disk space email alert?
Answer
You can use the included disk space alert script to send an email if the disk space utilized on the NPS host goes higher than the warning limit. To set up a warning when you are running out of disk space, follow these steps:
1. Copy the script below to any location on the NPS host. For purposes of this example, assume the script lives in /etc and is named disk-usage.sh.
2. Edit the script in VI, changing the email and dwarn parameters. Set email to the email address of the system administrator in the organization; set the dwarn value to the level at which you want to receive alerts, as a percentage of disk space utilized. For example, if the administrator wants to receive alerts when disk space utilized is at 85 percent (or higher):
- email=sysadmin@domain.com
dwarn=85
3. Save the file using wq! (write then quit).
4. Make the file executable by the following command:
- chmod 755 disk-usage.sh
5. Open the file (crontab –e) and make an entry to run the script disk-usage.sh every 30 minutes, as follows:
- */30 * * * * sh /etc/disk-usage.sh
The script will now run every 30 minutes, every day. Below is the contents of the script:
- ################## DISK SPACE ALERTS ##################
# Enter Sysadmin email address
email=sysadmin@domain.com
# Set percentage disk warning level; 85 or 90 is recommended
Dwarn=85
Redir=/tmp/disk
cat /dev/null > $Redir
# Redirecting host information in a File
echo "==========================" > $Redir
echo "====NPS SERVER DETAILS====" >> $Redir
echo "==========================" >> $Redir
echo -ne "\nHostName: " >> $Redir
hostname >> $Redir
echo -ne "\nIPaddress: " >> $Redir
hostname -i >> $Redir
echo -ne "\nDate: " >> $Redir
date | awk '{print $2, $3, $6, $4}' >> $Redir
echo -ne "\n" >> $Redir
echo -ne "Disk Utilization:\n" >> $Redir
echo -ne "\n" >> $Redir
echo -ne "Filesystem Size Used Avail Use% Mounted on\n" >> $Redir
df -H | grep -vE '^Filesystem|tmpfs|cdrom' >> $Redir
# Linux df command with extended commands for precise output
df -H | grep -vE '^Filesystem|tmpfs|cdrom' | awk '{ print $5 " " $1 }' | while read output;
do
echo $output
# Getting rid of % symbol
usep=$(echo $output | awk '{ print $1}' | cut -d'%' -f1 )
# Gathering Partition information
partition=$(echo $output | awk '{ print $2 }' )
# Matching used disk space with warning level
if [ $usep -ge $Dwarn ]; then
# Write Suggestion if disk usage is higher than disk warning limit in email content
echo -ne "\nSuggestion: Please Delete/Compress data to free up disk space on $partition!" >> $Redir
# Using netezza email client to send email to Sys Admin
/nz/kit/sbin/sendMail -dst $email -msg "WARNING! Disk Utilization for $partition is $usep%" -bodyTextFile "$Redir"
fi
done
###########################################################
Historical Number
NZ351481
Was this topic helpful?
Document Information
Modified date:
17 October 2019
UID
swg21577893