1. 程式人生 > >監控http服務腳本

監控http服務腳本

logs then pri nbsp scripts 腳本 如果 not have

[[email protected] scripts]# vim test_httpd.sh 
  1 #!/bin/bash
  2 #ss -tlnup|grep :80 >/dev/null 2>&1
  3 dk=$(ss -tlnup|awk -F"[ :]+" ‘/80/{print $5}‘)
  4 if [ "80" = "${dk}" ];then           #use string to compare,num is not have null
  5         echo "httpd is running"
  6 else
  7         echo "restarting"
  8         /etc/init.d/httpd restart >/dev/null 2>&1
  9 fi


如果服務沒起就重啟,if [ "80" = "${dk}" ];then 在字符串比較80 -eq dk 沒起是空的時候報錯,寫成字符串就不報錯應為字符串有空,數字沒值會報錯

監控http服務腳本