I am new to bash scripting, but I am working on a Unix AIX server and hoping to pull capacities for multiple environments on a single server; then run a conditional statement to compare those current capacities against my threshold variable, and then send an email notification if the capacity for specific environments is exceeded.
The problem I am having is with the conditional statement, and comparing my threshold against the output which is a column of capacity values. Any input would be greatly appreciated. Ultimately, I'd like to get this to the point where I can have the email specify which environments are exceeding capacity within the email. Then I can setup a cron job on multiple servers to run this script at specific times to automate our disk space management.
Any constructive feed back is welcomed and appreciated, I'm here to learn. Thanks in advance!
#!/bin/ksh
threshold=10
summary=$(df -Pg|grep -E 'opt|tmp|admin'|awk 'BEGIN {printf ("%- 40s %- 40s\n", "Partition", "Capacity") }{printf ("%- 40s %- 40s\n", $1, $5 )}')
date=$(date)
df -Pg|grep -E 'opt|tmp|admin'|awk '{print $5}'|sed 's/%//g'|while read -r output; do
if [ "$output" -ge "$threshold" ]; then
echo "$summary"|mailx -s "$date IMPORTANT:Disk Space Alert" JonMonJovi@abc.org
fi
done