gpt4 book ai didi

linux - 创建一个脚本守护进程来检查 httpd 服务是否打开或关闭

转载 作者:太空宇宙 更新时间:2023-11-04 06:00:44 24 4
gpt4 key购买 nike

检查 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)就像在后台运行的守护进程一样! 请帮忙

最佳答案

如果您使用 nohup 启动脚本,它将作为守护进程运行。

nohup script.sh &

关于linux - 创建一个脚本守护进程来检查 httpd 服务是否打开或关闭,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36791290/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com