[root@ob1 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 没起是空的时候报错,写成字符串就不报错应为字符串有空,数字没值会报错

相关文章:

  • 2021-10-13
  • 2021-11-30
  • 2021-07-01
  • 2021-09-30
  • 2022-01-01
  • 2022-12-23
  • 2022-12-23
  • 2021-07-28
猜你喜欢
  • 2021-03-31
  • 2022-12-23
  • 2021-08-15
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案