#!/bin/ksh # # get_fs_util - Get the percentage of filesystem utilization and send an alert # if the threshold is exceeded. # # version 0.07 # # Shane O'Neal (soneal@cisco.com), 4/4/2001 # # This script was tested on Solaris 2.6 and should run without # modification on newer versions of Solaris. Use on other platforms # will require modification. # # Release Notes: # # 0.07 - Added parameterization to utility for threshold, recipients # and file systems. You must pass in a file system. If no recipients # passed in, no email is sent. If no threshold is passed in, a default # of 80% is used. Also added to printing of info to standard output. # 0.06 - Fixed erroneous alerts with filesystems that do not exist. # 0.05 - Fixed erroneous alerts with filesystems less than 10% full. # The script ignores directories which do not exist. # 0.04 - Added syslog functionality and PATH statement. # 0.03 - The script no longer ignores filesystems that are 100% full. # # Directions: # # 1) Place this script in /usr/local/bin and make it executable: # # chmod 755 /usr/local/bin/get_fs_util # # 2) Modify the variables below to set the email RECIPIENTS, FILESYSTEMS # to be monitored (separated by a space if there are more than one), # filesystem utilization percentage THRESHOLD and syslog FACILITY. # # 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: THRESHOLD="85%" # Use a leading 0 if < 10% (ie. 09% rather than 9%) FACILITY="local7.err" USAGE="$0 [-t N] [-r Recipient List] mount_points..." RECIPIENTS="michael.pareene@setgetweb.com" while getopts ":t:r:" opt; do case $opt in t ) THRESHOLD=$OPTARG ;; r ) RECIPIENTS=$OPTARG ;; * ) echo $USAGE exit 1 ;; esac done shift $(($OPTIND - 1)) FILESYSTEMS=$* if [ -z $FILESYSTEMS ]; then echo $USAGE exit 1 fi # Do not modify anything below this line: PATH=/usr/bin:/usr/sbin:/bin:/usr/lib HOSTNAME=$(hostname | tr '[a-z]' '[A-Z]') for FS in $FILESYSTEMS do UTILIZED="" if [[ -d $FS ]]; then UTILIZED=$(df -k $FS | tail -1 | awk '{print $5}') fi if [[ "$UTILIZED" = [0-9]% ]]; then UTILIZED="0$UTILIZED" fi SUBJECT="Filesystem $FS on $HOSTNAME is $UTILIZED full!" MESSAGE="$SUBJECT Threshold is $THRESHOLD. Immediate System Administrator intervention is required." # Define the alert function: alert () { echo $MESSAGE logger -p $FACILITY -t get_fs_util \ "$FS is $UTILIZED full. Threshold is $THRESHOLD." if [ ! -z $RECIPIENTS ]; then echo $MESSAGE | mail -s "$SUBJECT" "$RECIPIENTS" fi } # Compare the utilized value against the threshold: if [[ "$UTILIZED" > "$THRESHOLD" || "$UTILIZED" = "100%" ]]; then alert fi done exit 0