前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >shell脚本-检查服务状态 原

shell脚本-检查服务状态 原

作者头像
阿dai学长
发布2019-04-03 11:06:01
1.2K0
发布2019-04-03 11:06:01
举报
文章被收录于专栏:阿dai_linux阿dai_linux

先判断是否安装http和mysql,没有安装进行安装,安装了检查是否启动服务,若没有启动则需要启动服务。

说明:操作系统为centos6,httpd和mysql全部为rpm包安装。

#!/bin/bash
##Checking whether http & mysql was installed.if yes,start them;if no,install them with yum 
## Written by Adai 2017-09-08
rpm -q http mysql > /tmp/pro_stat.txt
n=`cat /tmp/pro_stat.txt | grep '[0-9]' | wc -l`
if [ $n -eq 2 ]
then
    service mysql start
    service httpd start
else
    yum install -y mysql
    yum install -y httpd
    echo "The programs have been installed!"
fi

阿铭

#!/bin/bash
if_install()
{
    n=`rpm -qa|grep -cw "$1"`
    if [ $n -eq 0 ]
    then
    echo "$1 not install."
    yum install -y $1
    else
    echo "$1 installed."
    fi
}
if_install httpd
if_install mysql-server
chk_ser()
{
    p_n=`ps -C "$1" --no-heading |wc -l`
    if [ $p_n -eq 0 ]
    then
    echo "$1 not start."
    /etc/init.d/$1 start
    else
    echo "$1 started."
    fi
}
chk_httpd
chk_mysqld

(adsbygoogle = window.adsbygoogle || []).push({});

本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
原始发表:2017/09/14 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
相关产品与服务
云数据库 SQL Server
腾讯云数据库 SQL Server (TencentDB for SQL Server)是业界最常用的商用数据库之一,对基于 Windows 架构的应用程序具有完美的支持。TencentDB for SQL Server 拥有微软正版授权,可持续为用户提供最新的功能,避免未授权使用软件的风险。具有即开即用、稳定可靠、安全运行、弹性扩缩等特点。
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档