检查Httpd服务是否开启-shell脚本

首先要安装好http这个包,可以使用 yum -y install httpd 命令来进行安装 

#!/bin/bash

this_pid=$$

ss -luntp | grep httpd | grep -v "grep" | grep -v this_pid &> /dev/null

if [ $? -eq 0 ];then
	echo "The httpd service is running"
 else 
	echo "The httpd service is shutdown"
	read -p "Do you need to turn on httpd service?(yes or no) " switch
	
	if [ $switch == yes ];then
	  echo "Httpd service will run...Please wait for 3s"
	  systemctl start httpd
	  sleep 3

	   if [ $? -eq 0 ];then
	     echo "Httpd service is running"
	   else
	     echo "The service boot failure. please look for httpd_log"
	   fi

	else
	  echo "goodbye"
	  exit
	fi
fi

检查Httpd服务是否开启-shell脚本