巡检脚本

#!/bin/bash
time=`date "+%Y-%m-%d %H:%M:%S"`
hostname=`hostname`
total=`free -h | awk 'NR==2{print $2}'`
used=`free -h | awk 'NR==2{print $3}'`
hosts="1 2 3"
cpu_idle=`top -b -n 1 | grep Cpu | awk '{print $8}'|cut -f 1 -d "."`
cpu_use=`expr 100 - $cpu_idle`


echo "====================CPU==Memory===================="

echo  $time $hostname
echo "CPU 使用率:${cpu_use}%  CPU空闲:${cpu_idle}%"
echo "总内存$total,已使用内存$used"

echo "====================jar============================"

jars="sbsx-auth.jar sbsx-config.jar sbsx-daemon.jar sbsx-eureka.jar sbsx-gateway.jar sbsx-upms-biz.jar sunsmd-business.jar sunsmd-third.jar"

for jar in $jars;

do
  NR=`ps -ef |grep ${jar} |grep -v "grep" | wc -l`
  if [ "$NR" -eq 1 ];
  then
        echo "$jar 运行正常!"
  else
        echo "$jar 服务异常,请检查!!!"
  fi
done

for host in $hosts
do
echo "---------------------------------------------------------"
echo -e "\n"|telnet $host 6379|grep Connected > /dev/null 2>&1
if [ $? -eq 0 ];
then
echo "$host Redis service is ok!"
else
echo "$host Redis service is down!!!"
fi

echo -e "\n"|telnet $host 2181|grep Connected > /dev/null 2>&1
if [ $? -eq 0 ];
then
echo "$host Zookeeper service is ok!"
else
echo "$host Zookeeper service is down!!!"
fi

echo -e "\n"|telnet $host 8848|grep Connected > /dev/null 2>&1
if [ $? -eq 0 ];
then
echo "$host eureka  service is ok!"
else
echo "$host eureka  service is down!!!"
fi

echo "---------------------------------------------------------"
done

你可能感兴趣的:(巡检脚本)