#!/bin/bash

if [ $# -ne 1 ]; then
	echo
	echo "USAGE : `basename $0` <threshold(%)>"
	echo
	echo "        ./check_filesystem_usage.sh 60"
	echo
	exit 2
fi

threshold=${1}

### Check Filesystem Usage
fs_use_lists=`df -Ph | grep -v Filesystem | awk '{print $6,$5}'`

idx=1

for tmp in ${fs_use_lists}; do

	remNum=`expr ${idx} % 2`
	
	if [ ${remNum} -ne 0 ]; then
	
		fs_name=${tmp}
		
	else
	
		usage=`echo ${tmp} | cut -d ' ' -f 2 | cut -d '%' -f 1`
		#echo ${usage}
		
		if [ ${usage} -gt ${threshold} ]; then
			echo 'The '${fs_name}' filesystem is using '${usage}'% and exceeded threshold!!'
		fi
	
	fi
	
	idx=$((idx+1))
	
done