Apache 用于执行停止-启动多个httpd实例的shell脚本

Apache 用于执行停止-启动多个httpd实例的shell脚本,apache,shell,httpd.conf,Apache,Shell,Httpd.conf,我想编写一个脚本,仅当httpd实例处于运行状态时才重新启动它。例如,它工作正常,但不止一个实例失败 下面是我正在使用的脚本: ctl_var=`find /opt/apache/instances/ -name apachectl | grep -v "\/httpd\/"` ctl_proc=`ps -ef | grep -i httpd | grep -i " 1 " wc -l` if [ $ctl_proc <= 0 ]; then echo "httpd is no

我想编写一个脚本,仅当httpd实例处于运行状态时才重新启动它。例如,它工作正常,但不止一个实例失败

下面是我正在使用的脚本:

ctl_var=`find /opt/apache/instances/ -name apachectl  | grep -v "\/httpd\/"`

ctl_proc=`ps -ef | grep -i httpd | grep -i " 1 " wc -l`

if [ $ctl_proc <= 0 ]; 
  then echo "httpd is not running"; 
  else $ctl_var -k stop; echo "httpd stopped successfully" ;
  sleep 5;
  $ctl_var -k start;
  sleep 5;
  echo "httpd started" ps -ef | grep httpd | grep -i " 1 "; 
fi
ctl\u var=`find/opt/apache/instances/-name apachectl | grep-v“\/httpd\/”`
ctl|u proc=`ps-ef | grep-i httpd | grep-i“1”wc-l`

如果您提到的[$ctl_proc有多个实例,我看到它在执行脚本时错过了for循环。在这里,它只重新启动在$ctl_var中拾取的最后一个实例

修改后的脚本应如下所示,必要时调整脚本:

ctl_var=`find /opt/apache/instances/ -name apachectl  | grep -v "\/httpd\/"`
ctl_proc=`ps -ef | grep -i httpd | grep -i " 1 " wc -l`

for i in `echo $ctl_var`
do
    if [ $ctl_proc <= 0 ]; 
      then echo "httpd is not running"; 
      else $i -k stop; echo "httpd stopped successfully" ;
      sleep 5;
      $i -k start;
      sleep 5;
      echo "httpd started" ps -ef | grep httpd | grep -i " 1 "; 
    fi
done
ctl\u var=`find/opt/apache/instances/-name apachectl | grep-v“\/httpd\/”`
ctl|u proc=`ps-ef | grep-i httpd | grep-i“1”wc-l`
对于'echo$ctl_var'中的i`
做
如果[$ctl\U proc