现在的位置: 首页 > 脚本 > 正文

linux系统巡检脚本

2019年09月29日 脚本 ⁄ 共 4219字 ⁄ 字号 暂无评论

#!/bin/sh
#***************************************************************
#www.it598.net
#***************************************************************
#适用于rhel7/centos7
#ITEMCODE_START
#CHK_PORT:端口检查
#CHK_HSMNUM:err日志中关于加密机报错的条数检查
#CHK_ATMV_PRO:ATMV进程阀值为1检查
#CHK_PRO_1:非国密进程阀值为1检查
#CHK_PRO_3:非国密进程阀值为3检查
#CHK_PRO_5:非国密进程阀值为5检查
#COMM_CPU_VALUE:CPU空闲使用率 数字大于20
#COMM_MEMORY_VALUE:内存使用率 数字小于80
#COMM_FS_USAGE:文件系统使用率 数字小于80 结果集
#ITEMCODE_END

user="$USER"

Y=`date +"20%y%m%d"`
month=`date +%m`
day=`date +%d`
year=`date +%Y`
echo "当前用户为:"$user "DATE:"$Y

echo "COL_DETAIL_START:CHK_PORT"
port="9001"
key="0"
key=`netstat -ant | grep $port | wc -l`

if [ $key -eq 1 ]
then
#echo "$strip PORT $port IS LISTEN 【已开启】"
echo "PORTCHECK9001|+|OK"
else
#echo "$strip PORT $port NOT LISTEN 【未开启】"
echo "PORTCHECK9001|+|ERROR"
fi

port="9303"
key="0"
key=`netstat -ant | grep $port | wc -l`

if [ $key -eq 1 ]
then
#echo "$strip PORT $port IS LISTEN 【已开启】"
echo "ATMP_PORTCHECK9303|+|OK"
else
#echo "$strip PORT $port NOT LISTEN 【未开启】"
echo "PORTCHECK9303|+|ERROR"
fi
echo "COL_DETAIL_END:CHK_PORT"

echo "COL_DETAIL_START:CHK_PRO_1"
CHK_Bal9303=$(ps -ef|grep -w $LOGNAME|grep BalCommSrv30_9303|grep -v grep|wc -l)
echo -e "Bal9303|+|${CHK_Bal9303}"
CHK_Com701=$(ps -ef|grep -w $LOGNAME|grep CommClientSA_SL30_701|grep -v grep|wc -l)
echo -e "Com701|+|${CHK_Com701}"
CHK_Com704=$(ps -ef|grep -w $LOGNAME|grep CommClientSA_SL30_704|grep -v grep|wc -l)
echo -e "Com704|+|${CHK_Com704}"
CHK_Com705=$(ps -ef|grep -w $LOGNAME|grep CommClientSA_SL30_705|grep -v grep|wc -l)
echo -e "Com705|+|${CHK_Com705}"
echo "COL_DETAIL_END:CHK_PRO_1"

echo "COL_DETAIL_START:CHK_PRO_3"
CHK_worklog30=$(ps -ef|grep -w $LOGNAME|grep worklog30|grep -v grep|wc -l)
echo -e "worklog30|+|${CHK_worklog30}"
echo "COL_DETAIL_END:CHK_PRO_3"

echo "COL_DETAIL_START:CHK_PRO_5"
CHK_busi101=$(ps -ef|grep -w $LOGNAME|grep busi101|grep -v grep|wc -l)
echo -e "busi101|+|${CHK_busi101}"
CHK_busi102=$(ps -ef|grep -w $LOGNAME|grep busi102|grep -v grep|wc -l)
echo -e "busi102|+|${CHK_busi102}"
CHK_busi103=$(ps -ef|grep -w $LOGNAME|grep busi103|grep -v grep|wc -l)
echo -e "busi103|+|${CHK_busi103}"
CHK_busi104=$(ps -ef|grep -w $LOGNAME|grep busi104|grep -v grep|wc -l)
echo -e "busi104|+|${CHK_busi104}"
CHK_busi110=$(ps -ef|grep -w $LOGNAME|grep busi110|grep -v grep|wc -l)
echo -e "busi110|+|${CHK_busi110}"
CHK_busi111=$(ps -ef|grep -w $LOGNAME|grep busi111|grep -v grep|wc -l)
echo -e "busi111|+|${CHK_busi111}"
CHK_busi112=$(ps -ef|grep -w $LOGNAME|grep busi112|grep -v grep|wc -l)
echo -e "busi110|+|${CHK_busi112}"

CHK_Bal9001=$(ps -ef|grep -w $LOGNAME|grep BalCommSrv30_9001|grep -v grep|wc -l)
echo -e "Bal9001|+|${CHK_Bal9001}"
CHK_Com700=$(ps -ef|grep -w $LOGNAME|grep CommClientSA_SL30_700|grep -v grep|wc -l)
echo -e "Com700|+|${CHK_Com700}"

CHK_ch200=$(ps -ef|grep -w $LOGNAME|grep channel200|grep -v grep|wc -l)
echo -e "ch200|+|${CHK_ch200}"
CHK_ch201=$(ps -ef|grep -w $LOGNAME|grep channel201|grep -v grep|wc -l)
echo -e "ch201|+|${CHK_ch201}"
CHK_ch400=$(ps -ef|grep -w $LOGNAME|grep channel400|grep -v grep|wc -l)
echo -e "ch400|+|${CHK_ch400}"
CHK_ch401=$(ps -ef|grep -w $LOGNAME|grep channel401|grep -v grep|wc -l)
echo -e "ch401|+|${CHK_ch401}"
CHK_ch404=$(ps -ef|grep -w $LOGNAME|grep channel404|grep -v grep|wc -l)
echo -e "ch404|+|${CHK_ch404}"
CHK_ch406=$(ps -ef|grep -w $LOGNAME|grep channel406|grep -v grep|wc -l)
echo -e "ch406|+|${CHK_ch406}"

CHK_sw800=$(ps -ef|grep -w $LOGNAME|grep switch800|grep -v grep|wc -l)
echo -e "sw800|+|${CHK_sw800}"
CHK_sw801=$(ps -ef|grep -w $LOGNAME|grep switch801|grep -v grep|wc -l)
echo -e "sw801|+|${CHK_sw801}"

CHK_se841=$(ps -ef|grep -w $LOGNAME|grep secu841|grep -v grep|wc -l)
echo -e "se841|+|${CHK_se841}"
echo "COL_DETAIL_END:CHK_PRO_5"

echo "COL_DETAIL_START:CHK_ATMV_PRO"
CHK_ATMV_MMP=$(ps -ef|grep mmp|grep -v grep|wc -l)
echo -e "ATMV_MMP|+|${CHK_ATMV_MMP}"
CHK_ATMV_WEBSPHERE=$(ps -ef|grep WebSphere|grep -v grep|wc -l)
echo -e "ATMV_WEBSPHERE|+|${CHK_ATMV_WEBSPHERE}"
echo "COL_DETAIL_END:CHK_ATMV_PRO"

CHK_HSMNUM=$(grep -E -s 'GenerateMac err|Dec Pinblock err' $HOME/log/debug/error*|wc -l)
echo -e "RESULT:CHK_HSMNUM|+|${CHK_HSMNUM}"

#####CPU使用率#####
COMM_CPU_VALUE=$(sar 2 2 |grep -ivE "CPU" |tail -1|awk ' {print $NF}'|cut -d "." -f1)
echo "RESULT:COMM_CPU_VALUE|+|${COMM_CPU_VALUE}"

#####内存使用率#####
uesdMem1=`free -m|awk 'NR==2 {print $3}'`
totalMem=`free -m|awk 'NR==2 {print $2}'`
COMM_MEMORY_VALUE=`expr $uesdMem1 \* 100 / $totalMem`
echo "RESULT:COMM_MEMORY_VALUE|+|${COMM_MEMORY_VALUE}"

#####文件系统使用率#####
echo "COL_DETAIL_START:COMM_FS_USAGE"
df -hP|awk '{print $6"|+|"$5}'|grep -v Use%|cut -d'%' -f1
echo "COL_DETAIL_END:COMM_FS_USAGE"

给我留言

留言无头像?