栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 系统运维 > 运维 > Linux

Linux系统shell脚本之检测系统的任意服务

Linux 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

Linux系统shell脚本之检测系统的任意服务

Linux系统shell脚本之检测系统的任意服务
  • 一、脚本要求
  • 二、脚本内容
  • 三、执行脚本

一、脚本要求

1.输入任意一个服务名,如果服务运行和没运行输出提示
2.如果服务不存在,则提示

二、脚本内容
[root@192 practice]# cat service_input.sh 
#!/bin/bash
########################################
#Author:jeven
#time:Mon 30 May 2022 12:52:08 PM CST
#filename:service_input.sh
#Script description:
########################################
EX_RUN=$(systemctl list-units --type=service --state=running |awk '{print $1}' |cut -d "." -f1)
read -p "please input system service:"  service
for i in $EX_RUN
	do
		if [ $i = $service ];then
			echo "the $service  exist "
		fi
	done
echo $(systemctl list-units --type=service --state=running |awk '{print $1}' |cut -d "." -f1)|grep $service  &> /dev/null
if [ $? = 0 ];then
	echo "the $service is running"
	else 
		echo "the $service  not installed,please check your system"

	fi





三、执行脚本
[root@192 practice]# sh service_input.sh 
please input system service:a1a1a1a1
the a1a1a1a1  not installed,please check your system
[root@192 practice]# sh service_input.sh 
please input system service:httpd
the httpd  not installed,please check your system
[root@192 practice]# sh service_input.sh 
please input system service:mariadb
the mariadb  exist 
the mariadb is running
[root@192 practice]# 

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/940178.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号