create a dameon of a script that checks if httpd service is on or off [duplicate]

馋奶兔 提交于 2019-12-13 09:42:20

问题


Script to check if httpd is on or off

#!/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  

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


回答1:


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

nohup script.sh &


来源:https://stackoverflow.com/questions/36791290/unix-script-to-check-if-httpd-service-is-on-or-off-and-if-off-send-a-email

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!