Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/apache/8.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在centos 6关闭时重新启动Apache_Apache_Shell - Fatal编程技术网

在centos 6关闭时重新启动Apache

在centos 6关闭时重新启动Apache,apache,shell,Apache,Shell,我需要shell脚本在关闭时重新启动HTTPD。我在网上搜索发现了一些脚本,但它不工作,显示语法错误 #!/bin/bash RESTART="/sbin/service httpd restart" PGREP="/usr/bin/pgrep" HTTPD="httpd" $PGREP ${HTTPD} if [ $? -ne 0 ] # if apache not running then # restart apache $RESTART fi 当我运行这个脚本时,它会显示错误 [ro

我需要shell脚本在关闭时重新启动HTTPD。我在网上搜索发现了一些脚本,但它不工作,显示语法错误

#!/bin/bash
RESTART="/sbin/service httpd restart"
PGREP="/usr/bin/pgrep"
HTTPD="httpd"
$PGREP ${HTTPD}
if [ $? -ne 0 ] # if apache not running 
then
# restart apache
$RESTART
fi
当我运行这个脚本时,它会显示错误

[root@vmi194867 pydash]# bash -x /scripts/httpd.sh
: No such file or directory/usr/bin/pgrep // path is correct 
/scripts/httpd.sh: line 10: syntax error near unexpected token `fi'
/scripts/httpd.sh: line 10: `fi'

启动守护进程的脚本?但这已经存在了。。。类似于
sudo服务apache2 start
…并且顺便说一句:
restart
在daemin关闭时不会启动它。它无条件地重新启动,这意味着如果守护进程实际运行,您将中断当前服务的所有请求。
sudo-yum-whatprovides*/pgrep
…您能编写正确的代码并发送给我吗?我尝试了所有不起作用的操作