1badabing
asked on
Need help on a script that sends an email message on disk usage
Hello All
I am new to scripting and need help on writing a script that sends an email message on disk usage, can some help me to understand the basics and how to write this.
Please help me.
Requirements;
Create a script sends an email message to the user specified on the command line if any of the filesystems at more than 70% of capacity. The script should not process special filesystems as /proc. It should only process filesystems which are either locally mounted or are mounted via NFS.
An individual email should be sent for each filesystem which is at the warning level. There should be a subject on the email with a message "Warning: Filesystem <put filesystem the>here is at <X>% of capacity" If the filesystem is at greater than 90% of capacity, the "Warning" should be changed to "Critical Warning".
You may use any scripting language including /bin/sh, ksh, bash, awk or perl. Work done in the C-Shell (csh) will not be accepted.
I am new to scripting and need help on writing a script that sends an email message on disk usage, can some help me to understand the basics and how to write this.
Please help me.
Requirements;
Create a script sends an email message to the user specified on the command line if any of the filesystems at more than 70% of capacity. The script should not process special filesystems as /proc. It should only process filesystems which are either locally mounted or are mounted via NFS.
An individual email should be sent for each filesystem which is at the warning level. There should be a subject on the email with a message "Warning: Filesystem <put filesystem the>here is at <X>% of capacity" If the filesystem is at greater than 90% of capacity, the "Warning" should be changed to "Critical Warning".
You may use any scripting language including /bin/sh, ksh, bash, awk or perl. Work done in the C-Shell (csh) will not be accepted.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
And how much effort have you put towards researching this homework assignment? Show us what you've done thus far, and ask specific questions about what you don't understand.
ASKER
sorry for the delay, but i'm working on it to get post for review
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
I am still working on getting my script to be posted
ASKER
This is what I came up with, not sure how to eliminate the /proc (which I need to) and whether I will get to email to the destination. Someone please help me
#!/bin/bash
df -k | grep -v '^Filesystem | none' | awk '{ print $1 " " $5 }' | while read $output
do
echo $output
perc=$(echo $output | awk '{ print $2 }' | cut -d'%' –f2 )
part=$(echo $output | awk '{ print $1 }' )
if [ $perc -ge 90 ]; then
echo "Critical Warning: Filesystem \"$part\" at “$perc”% of capacity” | \
mail -s "Critical Warning: Filesystem \”$part\” at “$perc”% of capacity” 1badabing@expert.com
elif [ $perc -ge 70 ] && [ $perc -lt 90 ]; then
echo "Warning: Filesystem \"$part\" at “$perc”% of capacity” | \
mail -s "Warning: Filesystem \”$part\” at “$perc”% of capacity” 1badabing@expert.com
fi
done
#!/bin/bash
df -k | grep -v '^Filesystem | none' | awk '{ print $1 " " $5 }' | while read $output
do
echo $output
perc=$(echo $output | awk '{ print $2 }' | cut -d'%' –f2 )
part=$(echo $output | awk '{ print $1 }' )
if [ $perc -ge 90 ]; then
echo "Critical Warning: Filesystem \"$part\" at “$perc”% of capacity” | \
mail -s "Critical Warning: Filesystem \”$part\” at “$perc”% of capacity” 1badabing@expert.com
elif [ $perc -ge 70 ] && [ $perc -lt 90 ]; then
echo "Warning: Filesystem \"$part\" at “$perc”% of capacity” | \
mail -s "Warning: Filesystem \”$part\” at “$perc”% of capacity” 1badabing@expert.com
fi
done
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
please close
ASKER
nothiong yet