专注各种脚本编程
Baidu
加入收藏夹
本站内容有下面分类知识,欢迎您的到来^_^
shell相关:指令篇 基础篇 脚本欣赏 编程实例 shell问问 shell视频教程 技巧篇 水平测试 E文资料 vi编辑器 高级Bash脚本编程指南
其他:mysql perl c语言 oracle
当前位置:| 主页>shell脚本欣赏>

shell脚本自动重新启动已停止/僵死的Apache的httpd进程

百度收藏 QQ搜藏

原文:http://bash.cyberciti.biz/web-server/restart-apache2-httpd-shell-script/

适用操作系统版本:CentOS / RHEL / Fedora / Debian / Ubuntu Linux

我们使用pgrep命令查找系统进程中是否有httpd,确定apache有没有开启。

可以把脚本加入crontab文件中,参考下面设置:

*/5 * * * * /path/to/script.sh >/dev/null 2>&1

以下是该shell脚本的源代码:

#!/bin/bash
# Apache Process Monitor
# Restart Apache Web Server When It Goes Down
# -------------------------------------------------------------------------
# Copyright (c) 2003 nixCraft project <http://cyberciti.biz/fb/>
# This script is licensed under GNU GPL version 2.0 or above
# -------------------------------------------------------------------------
# RHEL / CentOS / Fedora Linux restart command
RESTART="service httpd restart"
 
# uncomment if you are using Debian / Ubuntu Linux
#RESTART="/etc/init.d/apache2 restart"
 
#path to pgrep command
PGREP="/usr/bin/pgrep"
 
# find httpd pid
$PGREP httpd
 
if [ $? -eq 0 ]
then
 # restart apache
 $RESTART
fi
上一篇:有菜单显示功能的shell脚本 下一篇:shell脚本使用随机变量生成随机命名的文件

power by soyo123 2007-2008