shell脚本-检测

#vim Cpu_check.sh

#!/bin/bash

read -p "please enter warn_val% : " warn_val
read -p "please enter serious_val% : " serious_val

expr ${warn_val} + 1 &> /dev/null
judge1=`echo $?`
expr ${warn_serious} + 1 &> /dev/null
judge2=`echo $?`

if [ ${judge1} -ne 0 -o ${judge2} -ne 0 ];then
	echo 'please enter number'
	exit 1
fi

if [ ${warn_val} -gt 100 -o ${serious_val} -gt 100 ];then
	echo 'please enter right number'
	exit 2
fi

cpu_val=`top n 5 b | grep %Cpu | awk '{print $8}'`

cpu_sum=0

for i in `seq 5`;do
	cpu=`echo ${cpu_val} | awk '{print $'"${i}"'}'`
	if [ ${cpu} == id, ];then
    	cpu=100.0
	fi
	cpu_sum=`echo ${cpu_sum} + ${cpu} | bc `
done

echo ${cpu_sum}

cpu_average=`echo "scale=1; ${cpu_sum}/5" | bc`

cpu_average_compare=`echo "${cpu_sum}/5" | bc`

echo ${cpu_average}

if [ ${cpu_average_compare} -le ${serious_val} ];then
	echo "cpu serious(cpu_free: ${cpu_average}%)"
elif [ ${cpu_average_compare} -le ${warn_val} ];then
	echo "cpu warn(cpu_free: ${cpu_average}%)"
fi

#vim disk_check.sh

#!/bin/bash
read -p "mount point('/','/boot','/dev'): " mount
read -p "warn(%): " warn
read -p "serious(%): " serious

if [ "${mount}" == "/" -o "${mount}" == '/boot' -o "${mount}" == '/dev' ];then
	used=`df -h | awk '/\'"${mount}"'$/{print $5}' | awk -F '%' '{print $1}'`
	echo "${mount} used: ${used}%"
else
	echo 'please enter correct mount point'
	exit 1
fi

expr ${warn} + 100 &> /dev/null
res1=`echo $?`
expr ${serious} + 100 &> /dev/null
res2=`echo $?`

if [ ${res1} -eq 0 -a ${res2} -eq 0 ];then
	if [ ${warn} -ge 100 -o ${serious} -ge 100 ];then
    	echo "please enter right value"
	elif [ ${used} -gt ${serious} ];then
    	echo "disk: ${mount} is overused"
	elif [ ${used} -gt ${warn} ];then
    	echo "disk: ${mount} is warnning"
	else
    	echo 'normal'
	fi
else
	echo 'please enter number'
fi

#vim mem_check.conf

#!/bin/bash

conf1="mem.conf"
while read line;do
	conf=`echo ${line}`


	if [ `echo ${conf} | awk /^#/` ];then
    	continue
	fi


	mem=`echo ${conf} | awk -F':' '{print $1}'`
	val_warn=`echo ${conf} | awk -F':' '{print $3}'`
	val_serious=`echo ${conf} | awk -F':' '{print $4}'`
	messages=`echo ${conf} | awk -F':' '{print $2}'`


	expr ${val_warn} + 100 &> /dev/null
	res1=`echo $?`
	expr ${val_serious} + 100 &> /dev/null
	res2=`echo $?`


	if [ ${res1} -ne 0 -o ${res2} -ne 0 ];then
    	echo "wrong mem.conf val"
    	break
	fi


	val_view=`free -h | grep -i ${mem} | awk '{print $NF}'`
	val_compare=`free | grep -i ${mem} | awk '{print $NF}'`
     

          
	if [ ${val_compare} -le ${val_serious} ];then
    	echo "${mem} is serious!   (${messages}:${val_view}) "
	elif [ ${val_compare} -le ${val_warn} ];then
    	echo "${mem} is warnning!  (${messages}:${val_view})"
	else
    	echo "${mem} is normal.    (${messages}:${val_view})"
	fi
	echo ' '

done < ${conf1}

#vim mem.conf

#name:state:val_warn:val_serious
mem : available : 800000 : 512000
swap:free:1048576:500000
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值