zl程序教程

您现在的位置是:首页 >  .Net

当前栏目

Shell系列(32)- 双分支if语句判断Apache服务是否启动

2023-02-18 16:27:25 时间
  • #!/bin/bash
  • #截取httped进程,并把结果赋予变量test
  • test=$(ps -aux | grep "httpd" | grep -v "grep")
  • #如果test的值不为空,则执行then中命令
  • if [ -n $"test" ]
  • then
  • echo "$(date) httped is ok!" >> /tmp/autostart-acc.log
  • else
  • /etc/rc.d/init.d/httpd start &> /dev/null
  • echo "$(date) restart httpd !" >> /tmp/autostart-err.log
  • fi