Script for Disk usage
We will discuss how to setup mail client and a script for disk usage alert
Step 1: Install mail client
sudo apt-get install mailutils # For Ubuntusudo yum install mailx # For RHEL,Centos
You will get prompts.Read the descriptions, Select the appropriate options.
Step 2: Create Disk Usage script.
cat > disk-usage.sh
#!/bin/sh
df -Ph | grep -vE ‘^Filesystem|tmpfs|cdrom’ | awk ‘{ print $5,$1 }’ | while read output;
do
echo $output
used=$(echo $output | awk ‘{print $1}’ | sed s/%//g)
partition=$(echo $output | awk ‘{print $2}’)
if [ $used -ge 80 ]; then
echo “The partition \”$partition\” on $(ip route get 1.2.3.4 | awk ‘{print $7}’) has used $used% at $(date)” | mail -s “Disk Space Alert: $used% Used On $(ip route get 1.2.3.4 | awk ‘{print $7}’)” <email-1>,<email2>
fi
donebash disk-usage.sh