创建检查脚本的dameon如果httpd服务是打开还是关闭 [英] create a dameon of a script that checks if httpd service is on or off

查看:155
本文介绍了创建检查脚本的dameon如果httpd服务是打开还是关闭的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

#!/bin/bash    
service=service_name  
email=user@domain.com     
host=`hostname -f`  
if (( $(ps -ef | grep -v grep | grep $service | wc -l) > 0 ))  
then  
echo "$service is running"  
else  
/etc/init.d/$service start  
if (( $(ps -ef | grep -v grep | grep $service | wc -l) > 0 ))  
then  
subject="$service at $host has been started"  
echo "$service at $host wasn't running and has been started" | mail -s   "$subject" $email  
else  
subject="$service at $host is not running"  
echo "$service at $host is stopped and cannot be started!!!" | mail -s   "$subject" $email  
fi  
fi  

如何使这个脚本在后台运行,使其保持检查是否httpd服务是打开还是关闭和电子邮件消息,如果它熄灭! (PS-:我不想作出一个cronjob脚本)就像它在后台运行的守护进程!
               请帮助

How do I make this script run in background so that it keeps checking if httpd service is on or off and emails a message if it goes off !! ( PS-: I DON'T WANT TO MAKE THE SCRIPT AS A CRONJOB) just like a daemon process which runs in background!! Please Help

推荐答案

如果您使用nohup的启动脚本,它会作为后台进程运行。

If you launch the script with nohup it will run as a daemon.

nohup script.sh &

这篇关于创建检查脚本的dameon如果httpd服务是打开还是关闭的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆