Apache service monitoring script ----- automatically restart apache

Source: Internet
Author: User
Apache service monitoring script ----- automatically restart apache [root @ localhostshell] viapache_monitorsh! Binbashwhile [1] dowgethttp: 127001 ahtml & gt; devnull2 & gt; & amp; 1if apache service monitoring script ----- automatically restart 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 2 done [root @ localhost shell] # cat/www/a.html OK [root @ localhost ~] # Lsof-I: 80 COMMAND 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 the apache service did not get up in about one or two seconds after I killed the httpd process, but it will soon be ready. if it is in actual production, you can change the sleep time in the script to 1. command pid user fd type device size node NAMEhttpd 618 root 3u IPv4 411612 TCP *: http (LISTEN) [root @ localhost ~] # Lsof-I: 80 COMMAND 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.20.a.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.20.a.html. 102 a.html. 181 a.html. 26 a.html. 338. ht Ml.416a.html. 103 a.html. 182 a.html. 260 a.html. 339 a.html.20.a.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. .................. I wiped the table and found that the table was cracked. I forgot that the script was not complete yet. I needed to take it all out. I also wanted to record the restart time and times of apache, so you need to change the script #! /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.html sleep 2 done then I start to test [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 shel L] # cat times.txt apache restart at 13-10-15 17: 47: 27 apache restart at 13-10-15 17:47:40 then I will change the.html content [root @ localhost www] # After cat a.html OKiii ---------- the content is not OK, the script is automatically re-downloaded once in two seconds [root @ localhost shell] # tail-f times.txt apache restart at 13-10-15 17: 47: 27 apache restart at 13-10-15 17: 47: 40 apache restart at 13-10-15 17: 48: 18 apache restart at 13-10-15 17: 48: 20 apache restart at 13-10-15 17: 48: 22 apache r Estart at 13-10-15 17: 48: 24 apache restart at 13-10-15 17: 48: 26 apache restart at 13-10-15 17: 48: 28 apache restart at 13-10-15 17: 48: 30 apache restart at 13-10-15 17: 48: 32 apache restart at 13-10-15 17: 48: 34 apache restart at 13-10-15 17: 48: 37 apache restart at 13-10-15 17: 48: 39 apache restart at 13-10-15 17: 48: 41 apache restart at 13-10-15 17: 48: 43 apache restart at 13-10-15 17: 48: 45 apache restart at 13-10 -15 17: 48: 47 apache restart at 13-10-15 17: 48: 49 apache restart at 13-10-15 17:48:51 [root @ localhost shell] # When I change back, the script stops log output, how many times have apache been restarted? [root @ localhost shell] # wc-l times.txt | cut-d ""-f119 ############## ###################################### write by the way A few simple scripts, interesting #! /Bin/basha = 1b = 5 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 ***************** write a simple script to get others' account and password #! /Bin/bashclearcat/etc/issue | head-1 echo-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.txt sleep 3 echo-e" \ n "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) brl. 18-194. el5 on an i686localhost login:
[Root @ localhost ~] # Cat/tmp/test.txt username: root password: asdf
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.