gpt4 book ai didi

linux - 在脚本中使用/etc/init.d/httpd 查找正在运行或未运行的 httpd

转载 作者:塔克拉玛干 更新时间:2023-11-03 00:01:02 27 4
gpt4 key购买 nike

我需要使用/etc/init.d/httpd status 命令来验证它是否在 shell 中运行。我不想使用 pidof pgrep 等——类似

retval=`/etc/init.d/httpd status`
if [ $retval -eq "running" ];then echo "yes" ; else echo "no";fi

有什么想法吗?

最佳答案

$? 将为您提供最近返回代码的值。例如

/etc/init.d/httpd status > /dev/null # ignore stdout
if [ $? -eq 0 ]; then
echo "yes"
else
echo "no"
fi

有关详细信息,请参阅 http://tldp.org/LDP/abs/html/exit-status.html

关于linux - 在脚本中使用/etc/init.d/httpd 查找正在运行或未运行的 httpd,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4668002/

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