首页 > 系统相关 >Linux健康检查脚本

Linux健康检查脚本

时间:2023-10-18 14:22:28浏览次数:37  
标签:脚本 Status grep Normal ps YELLOW echo Linux 健康检查

脚本内容如下:

[root@zabbix-agent scritps]# cat healthcheck.sh
#! /bin/bash
#color notes
Normal='\033[0m'
GREEN='\033[0;32m'
RED='\033[0;31m'
YELLOW='\033[0;33m'
cyan='\033[0;36m'
yellow='\033[0;33m'
#Sectioning .........
echo -e "${YELLOW}---------------------------------------------------------------------------------------------------------------${Normal}"
echo "Server details:"
echo -e "${YELLOW}---------------------------------------------------------------------------------------------------------------${Normal}"

#fetching basic specs from the server(user,ip,os)
user=`whoami`
echo -e "${cyan}User:${Normal} $user"
hostname=`hostname`
echo -e "${cyan}hostname:${Normal} $hostname"
ip=`hostname -I`
echo -e "${cyan}IP address:${Normal} $ip"
os=`cat /etc/os-release | grep 'NAME\|VERSION' | grep -v 'VERSION_ID' | grep -v 'PRETTY_NAME' | grep NAME`
echo -e "${cyan}OS:${Normal} $os"

#Sectioning.....
echo -e "${YELLOW}---------------------------------------------------------------------------------------------------------------${Normal}"
echo "Service status:"
echo -e "${YELLOW}---------------------------------------------------------------------------------------------------------------${Normal}"
sleep 1

#checking tomcat status
echo -e "${yellow}1) Tomcat${Normal}"
#grepping tomcat status from ps aux
pp=`ps aux | grep tomcat | grep "[D]java.util"`
if [[ $pp =~ "-Xms512M" ]];then
echo -e " Status: ${GREEN}UP${Normal}"
else
echo -e " Status: ${RED}DOWN${Normal}"
fi
echo ""
#function to check apache is running or not!
function apache() {
echo -e "${yellow}2) Apache-httpd${Normal}"
#grepping apache status from ps aux
httpd=`ps aux | grep httpd | grep apache`
if [[ $httpd =~ "apache" ]];then
echo -e " Status: ${GREEN}UP${Normal}"
else
echo -e " Status: ${RED}DOWN${Normal}"
fi
}

#function to check elastic is running or not
function elastic() {
echo -e "${yellow}3) Elasticsearch${Normal}"
#grepping elasticsearch status from ps aux
elastic=`ps aux | grep elasticsearch`
if [[ $elastic =~ "elastic+" ]];then
echo -e " Status: ${GREEN}UP${Normal}"
else
echo -e " Status: ${RED}DOWN${Normal}"
fi
#function to check mysql is running or not
}
function mysql() {
echo -e "${yellow}4) Mysql${Normal}"
#grepping mysql status from ps aux
mysql=`ps aux | grep mysqld`
if [[ $mysql =~ "mysqld" ]];then
echo -e " Status: ${GREEN}UP${Normal}"
else
echo -e " Status: ${RED}DOWN${Normal}"
fi
}

function docker() {
echo -e "${yellow}5) Docker${Normal}"
#grepping docker status from ps aux
docker=`systemctl status docker | grep dead`
if [[ $docker =~ "dead" ]];then
echo -e " Status: ${GREEN}UP${Normal}"
else
echo -e " Status: ${RED}DOWN${Normal}"
fi
}
#calling functions
apache
echo ""
elastic
echo ""
mysql
echo ""
docker
echo ""
#Sectioning............
#Fetching mem and cpu informations
echo -e "${YELLOW}---------------------------------------------------------------------------------------------------------------${Normal}"
echo "Memory Details:"
echo -e "${YELLOW}---------------------------------------------------------------------------------------------------------------${Normal}"
sleep 1
#view mem info
free -h
#get uptime details
uptime=$(uptime | awk '{print $3,$4}' | cut -f1 -d,)
echo -e "${cyan}System Uptime:${Normal} :$uptime"
#Fetching the load averageloadaverage=$(top -n 1 -b | grep "load average:" | awk '{print $10 $11 $12}')
echo -e "${cyan}Load average:${Normal}: $loadaverage"
echo -e "${cyan}The top 10 services with high resource usage are listed below.${Normal}"
#Get top services with high resource utilization
ps -eo pid,ppid,cmd,%mem,%cpu --sort=-%mem | head

#sectioning...........
#Fetching server space details!
echo -e "${YELLOW}---------------------------------------------------------------------------------------------------------------${Normal}"
echo "Server space Details:"
echo -e "${YELLOW}---------------------------------------------------------------------------------------------------------------${Normal}"
#View disk space details
df -h
echo "----------------------------------------------------------------------------------------------------------------"gg
[root@zabbix-agent scritps]#
[root@zabbix-agent scritps]# cat healthcheck.sh
#! /bin/bash
#color notes
Normal='\033[0m'
GREEN='\033[0;32m'
RED='\033[0;31m'
YELLOW='\033[0;33m'
cyan='\033[0;36m'
yellow='\033[0;33m'
#Sectioning .........
echo -e "${YELLOW}---------------------------------------------------------------------------------------------------------------${Normal}"
echo "Server details:"
echo -e "${YELLOW}---------------------------------------------------------------------------------------------------------------${Normal}"

#fetching basic specs from the server(user,ip,os)
user=`whoami`
echo -e "${cyan}User:${Normal} $user"
hostname=`hostname`
echo -e "${cyan}hostname:${Normal} $hostname"
ip=`hostname -I`
echo -e "${cyan}IP address:${Normal} $ip"
os=`cat /etc/os-release | grep 'NAME\|VERSION' | grep -v 'VERSION_ID' | grep -v 'PRETTY_NAME' | grep NAME`
echo -e "${cyan}OS:${Normal} $os"

#Sectioning.....
echo -e "${YELLOW}---------------------------------------------------------------------------------------------------------------${Normal}"
echo "Service status:"
echo -e "${YELLOW}---------------------------------------------------------------------------------------------------------------${Normal}"
sleep 1

#checking tomcat status
echo -e "${yellow}1) Tomcat${Normal}"
#grepping tomcat status from ps aux
pp=`ps aux | grep tomcat | grep "[D]java.util"`
if [[ $pp =~ "-Xms512M" ]];then
echo -e " Status: ${GREEN}UP${Normal}"
else
echo -e " Status: ${RED}DOWN${Normal}"
fi
echo ""
#function to check apache is running or not!
function apache() {
echo -e "${yellow}2) Apache-httpd${Normal}"
#grepping apache status from ps aux
httpd=`ps aux | grep httpd | grep apache`
if [[ $httpd =~ "apache" ]];then
echo -e " Status: ${GREEN}UP${Normal}"
else
echo -e " Status: ${RED}DOWN${Normal}"
fi
}

#function to check elastic is running or not
function elastic() {
echo -e "${yellow}3) Elasticsearch${Normal}"
#grepping elasticsearch status from ps aux
elastic=`ps aux | grep elasticsearch`
if [[ $elastic =~ "elastic+" ]];then
echo -e " Status: ${GREEN}UP${Normal}"
else
echo -e " Status: ${RED}DOWN${Normal}"
fi
#function to check mysql is running or not
}
function mysql() {
echo -e "${yellow}4) Mysql${Normal}"
#grepping mysql status from ps aux
mysql=`ps aux | grep mysqld`
if [[ $mysql =~ "mysqld" ]];then
echo -e " Status: ${GREEN}UP${Normal}"
else
echo -e " Status: ${RED}DOWN${Normal}"
fi
}

function docker() {
echo -e "${yellow}5) Docker${Normal}"
#grepping docker status from ps aux
docker=`systemctl status docker | grep dead`
if [[ $docker =~ "dead" ]];then
echo -e " Status: ${GREEN}UP${Normal}"
else
echo -e " Status: ${RED}DOWN${Normal}"
fi
}
#calling functions
apache
echo ""
elastic
echo ""
mysql
echo ""
docker
echo ""
#Sectioning............
#Fetching mem and cpu informations
echo -e "${YELLOW}---------------------------------------------------------------------------------------------------------------${Normal}"
echo "Memory Details:"
echo -e "${YELLOW}---------------------------------------------------------------------------------------------------------------${Normal}"
sleep 1
#view mem info
free -h
#get uptime details
uptime=$(uptime | awk '{print $3,$4}' | cut -f1 -d,)
echo -e "${cyan}System Uptime:${Normal} :$uptime"
#Fetching the load averageloadaverage=$(top -n 1 -b | grep "load average:" | awk '{print $10 $11 $12}')
echo -e "${cyan}Load average:${Normal}: $loadaverage"
echo -e "${cyan}The top 10 services with high resource usage are listed below.${Normal}"
#Get top services with high resource utilization
ps -eo pid,ppid,cmd,%mem,%cpu --sort=-%mem | head

#sectioning...........
#Fetching server space details!
echo -e "${YELLOW}---------------------------------------------------------------------------------------------------------------${Normal}"
echo "Server space Details:"
echo -e "${YELLOW}---------------------------------------------------------------------------------------------------------------${Normal}"
#View disk space details
df -h
echo "----------------------------------------------------------------------------------------------------------------"gg
[root@zabbix-agent scritps]#

 

 

日常健康巡检脚本执行效果如下:

 

标签:脚本,Status,grep,Normal,ps,YELLOW,echo,Linux,健康检查
From: https://www.cnblogs.com/cherishthepresent/p/17772247.html

相关文章

  • linux centos7kettle使用Carte
    1.下载安装kettle的方法请自行百度2.启动carte服务进入kettle目录cd/opt/data-integration方式一#windowsCarte.batipport#例:Carte.bat 192.168.x.x 8080#linux./carte.shipport#例:./carte.sh 192.168.x.x 8080方式二编辑data-integration/pwd/carte-confi......
  • linux安装中文字体
    以最常用的宋体为例:1、下载simsun.ttf链接https://github.com/npqzxc/FontSimsun2、进入服务器目录/usr/share/fonts创建chinese文件夹3、将simsun.ttf文件放入文件夹中  4、chmod-R755/usr/share/fonts/chinese5、执行mkfontscale6、执行fc-list:lang=zh查看有数......
  • 【Linux常用命令5】文本文件编辑命令
    stat命令:查看文件详细信息的命令stat[选项]文件参数含义-L支持符号链接-f显示文件系统的信息-t以简洁的方式输出--help显示命令帮助信息--version显示命令版本信息示例:[root@izb1j05w8ldmtn1ylavvdfzmpaas]#statzhuque2tj.jsonFile:......
  • 实验二 Linux命令使用(二)
    实验内容及步骤:(1)进入家目录,创建自己的子目录,进入该子目录,运行date>file1,然后运行catfile1,看到什么信息?“>”是什么符号?答:输出重定向操作符解释“date>file1”的含义:答:将当前日期和时间写入名为file1的文件中。(2)运行mandate>>file1,再运行catfile1,看到什么?mandat......
  • OpenStack CentOS 7 一键安装脚本
    一键安装脚本,可以复制粘贴挥着下载install.sh文件,传到服务器进行安装就行  #!/bin/bashyumupdateyuminstall-ywget#使用wget命令下载wget-O/etc/yum.repos.d/CentOS-Base.repohttp://mirrors.aliyun.com/repo/Centos-7.repoyumupdate注意:如果没有wget命令,请......
  • 布尔盲注万能脚本
    来自:[WUSTCTF2020]颜值成绩查询脚本如下(python)使用时修改为自己的Success_message,url,以及re的正则规则即可。importtimeimportrequestsimportreSuccess_message="Hi"defcont(text):obj=re.compile(r'<h2class="mb">(?P<xiao>.*?)</h2>&#......
  • linux centos7 安装mysql
    home目录下新建安装包存放位置cdhomemkdirinstall_packetcd/home/install_packet下载mysql5.7rpm源wgethttp://repo.mysql.com/mysql57-community-release-el7-8.noarch.rpm安装下载好的rpm包rpm-ivhmysql57-community-release-el7-8.noarch.rpm安装mysqly......
  • linux centos7安装docker
    1.运行以下命令,下载docker-ce的yum源sudowget-O/etc/yum.repos.d/docker-ce.repohttps://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo2.运行以下命令,安装Docker。sudoyum-yinstalldocker-ce3.执行以下命令,检查Docker是否安装成功。sudodocker-......
  • linux centos7用 yum安装nginx
    1.nginx中加入nginx软件包yuminstallepel-releaseyumupdate2.安装nginxyum-yinstallnginx 3.查看nginx相关目录(可跳过)whereisnginx4.启动nginxsystemctlstartnginx5.nginx停止重启平滑重启命令systemctlstopnginxsystemctlrestartngi......
  • linux yum 安装redis
    安装启动redis并设置开机自动启动yuminstall-yepel-release&&sleep3&&yuminstall-yredis&&systemctlenable--nowredis查看redis服务器状态systemctlenableredis 开放防火墙端口号(若已关闭防火墙请略过)firewall-cmd--zone=public--add-port=80/t......