#!/bin/bash# 获取运行状态http=$(systemctl status httpd | grep Active | awk '{print $2}')# 判断运行状态if [ "$http" != "active" ];then# 运行状态为失败时尝试重启并发出重启成功信息,如果运行失败发出失败警告!systemctl restart httpd && echo "httpd Restart successfully" || echo "httpd Unable to restart"exit 0else# 判断如果运行状态为正常发出正常信息echo "httpd Normal operation"exit 1fi