监测Apache是否run否则启动-脚本

2019年6月28日

查看Apache 状态是否启动 没有启动则启动 并记录日志

#!/bin/sh
curdate=`date +"%Y-%m-%d %H:%M:%S"`
echo "#====================================================================" >> /home/shell/apache/status.log 2>&1 &
echo $curdate "Check httpd start " >> /home/shell/apache/status.log 2>&1 &
echo " " >> /home/shell/apache/status.log 2>&1 &

 

num=`ps -ef|grep "httpd"|grep -v grep|wc -l`
#num2=`ps -ef|grep "httpd" | grep -v grep |wc -l`
#num3=`netstat -anopt | grep 8080 | wc -l`

if [ ${num} -lt 1 ] ;then
echo $curdate >> /home/shell/apache/status.log 2>&1 &
echo "-----------------------" >> /home/shell/apache/status.log 2>&1 &
echo "service httpd start" >> /home/shell/apache/status.log 2>&1 &
service httpd start
echo "-----------------------" >> /home/shell/apache/status.log 2>&1 &
else
echo "apache/httpd is running "$curdate >> /home/shell/apache/status.log 2>&1 &
fi

# apache Complicating large
if [ ${num} -gt 700 ] ;then
echo $curdate"this timestamp is index full (${num})" >> /home/shell/apache/status.log 2>&1 &

echo "-----------------------" >> /home/shell/apache/status.log 2>&1 &
echo "service httpd stop" >> /home/shell/apache/status.log 2>&1 &
service httpd stop
echo "-----------------------" >> /home/shell/apache/status.log 2>&1 &
echo " " >> /home/shell/apache/status.log 2>&1 &
sleep 3
echo " " >> /home/shell/apache/status.log 2>&1 &
echo "-----------------------" >> /home/shell/apache/status.log 2>&1 &
echo "service httpd start" >> /home/shell/apache/status.log 2>&1 &
service httpd start
echo "-----------------------" >> /home/shell/apache/status.log 2>&1 &
else
echo "apache/httpd is running and apache Complicating Normal "$curdate >> /home/shell/apache/status.log 2>&1 &
fi

#if [ ${num2} -lt 2 ] ;then
# echo $curdate >> /home/shell/apache/status.log 2>&1 &
# killall -9 httpd
# service httpd start
#else
# echo "httpd is running "$curdate >> /home/shell/apache/status.log 2>&1 &
#fi

#if [ ${num2} -gt 450 ] ;then
# echo $curdate "this timestamp is for the forum's conection full (${num})" >> /home/shell/apache/status.log 2>&1 &
# killall -9 httpd
# sleep 3
# service httpd start
#else
# echo "httpd is running "$curdate >> /home/shell/apache/status.log 2>&1 &
#fi

echo "" >> /home/shell/apache/status.log 2>&1 &
echo $curdate "Check httpd stop " >> /home/shell/apache/status.log 2>&1 &
echo "#====================================================================" >> /home/shell/apache/status.log 2>&1 &
echo "" >> /home/shell/apache/status.log 2>&1 &

没有评论

发表回复

您的电子邮箱地址不会被公开。 必填项已用 * 标注