- 一、脚本要求
- 二、脚本内容
- 三、执行脚本
二、脚本内容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]#



