96 lines
2.5 KiB
Bash
Executable File
96 lines
2.5 KiB
Bash
Executable File
#!/usr/bin/ksh
|
|
#
|
|
# SCRIPT: linux_swap_mon.ksh
|
|
#
|
|
# AUTHOR: Randy Michael
|
|
# DATE: 5/31/2007
|
|
# REV: 1.1.P
|
|
#
|
|
# PLATFORM: Solaris Only
|
|
#
|
|
# PURPOSE: This shell script is used to produce a report of
|
|
# the system's paging space statistics including:
|
|
#
|
|
# Total paging space in MB, MB of Free paging space,
|
|
# MB of Used paging space, % of paging space Used, and
|
|
# % of paging space Free
|
|
#
|
|
# REV LIST:
|
|
#
|
|
#
|
|
# set -x # Uncomment to debug this shell script
|
|
# set -n # Uncomment to check command syntax without any execution
|
|
#
|
|
###########################################################
|
|
################ DEFINE VARIABLES HERE ####################
|
|
|
|
PC_LIMIT=65 # Upper limit of Swap space percentage
|
|
# before notification
|
|
THISHOST=$(hostname) # Host name of this machine
|
|
|
|
###########################################################
|
|
################ INITIALIZE THE REPORT ####################
|
|
|
|
echo "\nSwap Space Report for $THISHOST\n"
|
|
date
|
|
|
|
###########################################################
|
|
############# CAPTURE AND PROCESS THE DATA ################
|
|
|
|
# Use two awk statements to extract the $9 and $11 fields
|
|
# from the swap -s command output
|
|
|
|
SW_USED=$(swap -s | awk '{print $9}' | cut -dk -f1)
|
|
SW_FREE=$(swap -s | awk '{print $11}' | cut -dk -f1)
|
|
|
|
# Add SW_USED to SW_FREE to get the total swap space
|
|
|
|
((SW_TOTAL = SW_USED + SW_FREE))
|
|
|
|
# Calculate the percent used and percent free using the
|
|
# bc utility in a here documentation with command substitution
|
|
|
|
PERCENT_USED=$(bc <<EOF
|
|
scale=4
|
|
($SW_USED / $SW_TOTAL) * 100
|
|
EOF
|
|
)
|
|
|
|
PERCENT_FREE=$(bc <<EOF
|
|
scale=4
|
|
($SW_FREE / $SW_TOTAL) * 100
|
|
EOF
|
|
)
|
|
|
|
# Convert the KB measurements to MB measurements
|
|
|
|
((SW_TOTAL_MB = SW_TOTAL / 1000))
|
|
((SW_USED_MB = SW_USED / 1000))
|
|
((SW_FREE_MB = SW_FREE / 1000))
|
|
|
|
# Produce the remaining part of the report
|
|
|
|
echo "\nTotal Amount of Swap Space:\t${SW_TOTAL_MB}MB"
|
|
echo "Total KB of Swap Space Used:\t${SW_USED_MB}MB"
|
|
echo "Total KB of Swap Space Free:\t${SW_FREE_MB}MB"
|
|
echo "\nPercent of Swap Space Used:\t${PERCENT_USED}%"
|
|
echo "\nPercent of Swap Space Free:\t${PERCENT_FREE}%"
|
|
|
|
# Grab the integer portion of the percent used
|
|
|
|
INT_PERCENT_USED=$(echo $PERCENT_USED | cut -d. -f1)
|
|
|
|
# Check to see if the percentage used maxmum threshold
|
|
# has beed exceeded
|
|
|
|
if (( PC_LIMIT <= INT_PERCENT_USED ))
|
|
then
|
|
# Percent used has exceeded the threshold, send notification
|
|
|
|
tput smso # Turn on reverse video!
|
|
echo "\n\nWARNING: Swap Space has Exceeded the ${PC_LIMIT}% Upper Limit!\n"
|
|
tput rmso # Turn off reverse video!
|
|
fi
|
|
|
|
echo "\n"
|