清华大佬耗费三个月吐血整理的几百G的资源,免费分享!....>>>
#!/bin/sh
##################################################################################
#FileName: nmon_monitor.sh
#Author: Defias
#Date 2014-12-2
#example:./nmon.sh -m 30 ./nmon.sh -h 1 ./
##################################################################################
nmonpage_name="nmon_linux_14i.tar.gz"
nmon_name="nmon_x86_64_rhel54"
usage()
{
echo "usage: $0 -m|-h minute|hour"
}
check_pid()
{
#进程检查
nmonpid=`ps -ef | grep ${nmon_name} | grep -v grep | awk '{print $2}'`
#echo "nmonpid is ${nmonpid}"
if [ -n "${nmonpid}" ];then
echo "process nmon is running!"
echo "kill process nmon? y/n"
while true
do
read x
case "$x" in
y | yes | Y | Yes | YES)
kill -9 $nmonpid
if [ $? != 0 ];then
echo "kill -9 $nmonpid fail!"
exit -1
fi
#echo "kill -9 $nmonpid success!"
break
;;
n | no | N | No | NO)
echo "nothing to do!"
exit -1
;;
*)
echo "Please enter yes or no"
;;
esac
done
fi
}
#参数检查
if [ $# -ne 2 ];then
usage
exit 1
fi
opt="$1"
optdata="$2"
if [ ! ${optdata} -eq ${optdata} ]; then
echo "$optdata is not a number"
usage
exit 1
fi
#进程检查
check_pid
#包解压
if [ ! -f $nmonpage_name ];then
echo "don't find $nmonpage_name file! "
exit 1
fi
chmod 775 $nmonpage_name
pwdpath=`pwd`
if [ ! -d ${pwdpath}/bin ];then
mkdir ${pwdpath}/bin
fi
nmonpath="${pwdpath}/bin/"
if [ ! -d ${pwdpath}/logs ];then
mkdir ${pwdpath}/logs
fi
logpath="${pwdpath}/logs/"
tar -zxvf $nmonpage_name -C $nmonpath > /dev/null
#启动nmon监控
case "$opt" in
-m)
if [ $optdata -le 60 ];then
ntime=$((${optdata} * 60 / 2))
${nmonpath}${nmon_name} -fT -s 2 -c $ntime -m $logpath
elif [ $optdata -le 600 ];then
ntime=$((${optdata} * 60 / 5))
${nmonpath}${nmon_name} -fT -s 5 -c $ntime -m $logpath
elif [ ${optdata} -le 1440 ];then
ntime=$((${optdata} * 60 / 10))
${nmonpath}${nmon_name} -fT -s 10 -c $ntime -m $logpath
else
ntime=$((${optdata} * 60 / 15))
${nmonpath}${nmon_name} -fT -s 15 -c $ntime -m $logpath
fi
echo "nmon monitor success!"
;;
-h)
if [ $optdata -le 1 ];then
ntime=$((${optdata} * 60 * 60 / 2))
${nmonpath}${nmon_name} -fT -s 2 -c $ntime -m $logpath
elif [ $optdata -le 10 ];then
ntime=$((${optdata} * 60 * 60 / 5))
${nmonpath}${nmon_name} -fT -s 5 -c $ntime -m $logpath
elif [ ${optdata} -le 24 ];then
ntime=$((${optdata} * 60 * 60 / 10))
${nmonpath}${nmon_name} -fT -s 10 -c $ntime -m $logpath
else
ntime=$((${optdata} * 60 * 60 / 15))
${nmonpath}${nmon_name} -fT -s 15 -c $ntime -m $logpath
fi
echo "nmon monitor success!"
;;
*)
echo "$opt is error!"
usage
;;
esac