nmon监控脚本

下面是编程之家 jb51.cc 通过网络收集整理的代码片段。

编程之家小编现在分享给大家,也给大家做个参考。

#!/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

以上是编程之家(jb51.cc)为你收集整理的全部代码内容,希望文章能够帮你解决所遇到的程序开发问题。

如果觉得编程之家网站内容还不错,欢迎将编程之家网站推荐给程序员好友。

相关文章

系ubuntu 下面打开终端输入:sudo apt-get install sendmail...
依家我有1个软件goagent目录(大家懂得) 放在/home/gateman/...
其实我想讲的是 cp -L关于-L参数的解释:-L, --dereferenc...
原地址:http://www.rjgc.net/control/content/content.php?...
chroot,即 change root directory (更改 root 目录)。在 li...
简单解析下, stdin就是标准输入, stdout就是标准。举个例子...