vi /usr/local/bin/get_fs_util
i(insert)
Paste the below
Basically just change the email and threshold, setup cron and your done!
Crontab -e -> insert the below for every 15 min checks
0,15,30,45 * * * * /usr/local/bin/get_fs_util >/dev/null 2>&1
Crontab -e -> insert the below for every 15 min checks
0,15,30,45 * * * * /usr/local/bin/get_fs_util >/dev/null 2>&1
# if the threshold is exceeded.
#
#
# Directions:
#
# 1) Place this script in /usr/local/bin and make it executable:
# vi /usr/local/bin/get_fs_util
#
#
# chmod 755 /usr/local/bin/get_fs_util
#
# 2) Modify the variables below to set the email RECIPIENT, FILESYSTEMS
# to be monitored (separated by a space if there are more than one)
# and filesystem utilization percentage THRESHOLD.
#
# 3) Add a line to root's crontab similar to the following:
#
# 0,15,30,45 * * * * /usr/local/bin/get_fs_util >/dev/null 2>&1
#
# In this example, this script will run every 15 minutes.
#
# NOTE: The script does not have to be run by root. It can be run by
# any user.
#
# 4) To test the script, change the THRESHOLD to a value lower than the
# current utilized capacity, as reported by "df -k", and run the script
# from the command line.
#
# User modifiable variables:
RECIPIENT="sysadmin@sitesnstores.com.au"
# change file systems to monitor below...
FILESYSTEMS="/" (You can check this with '# df -h' and you can select where you want to check)
THRESHOLD="20%"
# Do not modify anything below this line:
HOSTNAME=$(hostname | /usr/bin/tr '[a-z]' '[A-Z]')
for FS in $FILESYSTEMS
do
UTILIZED=$(df -k $FS | /usr/bin/tail -1 | /usr/bin/awk '{print $5}')
SUBJECT="Filesystem $FS on $HOSTNAME is $UTILIZED full!"
MESSAGE="$SUBJECT Threshold is $THRESHOLD. Immediate System Administrator intervention is required."
# Define the email function:
mail_alert ()
{
echo $MESSAGE | /bin/mail -s "$SUBJECT" "$RECIPIENT"
}
# Compare the utilized value against the threshold:
if [[ "$UTILIZED" > "$THRESHOLD" || "$UTILIZED" = "100%" ]]; then
mail_alert
fi
done
exit 0
No comments:
Post a Comment