Linux系统shell脚本之检测系统的任意服务
Posted 江湖有缘
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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]#
以上是关于Linux系统shell脚本之检测系统的任意服务的主要内容,如果未能解决你的问题,请参考以下文章