#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