/de-6ren">
gpt4 book ai didi

linux - CentOS 7 pidof -x 不工作

转载 作者:太空宇宙 更新时间:2023-11-04 09:23:48 29 4
gpt4 key购买 nike

我有一个 CentOS 7 服务器虚拟机。在这个 VM 中,我安装了 Apache Apollo

我刚刚创建了下面给出的脚本

#!/bin/bash

if pidof -x "apollo" >/dev/null; then
echo "Apollo MQTT is Running."
exit 0
else
echo "Apollo MQTT is Stopped."
exit 2
fi

使用上面的脚本我想检查 apollo 服务是否正在运行。但是当我使用下面的命令运行这个脚本时

sh filename

它在服务运行时给出输出 Apollo MQTT is Stopped

当我在命令下运行时

ps -ef | grep apollo

它给出以下输出

root       8647      1  3 10:49 pts/0    00:00:55 java -ea -server -Xmx1G -XX:+HeapDumpOnOutOfMemoryError -XX:-UseBiasedLocking -Dcom.sun.management.jmxremote -Dapollo.home=/opt/apollo -Dapollo.base=/var/lib/mqtt -classpath /opt/apollo/lib/apollo-boot.jar org.apache.activemq.apollo.boot.Apollo /var/lib/mqtt/lib\;/opt/apollo/lib org.apache.activemq.apollo.cli.Apollo run
root 9426 8233 0 11:15 pts/0 00:00:00 grep --color=auto apollo

最佳答案

你可以用这个;

if (( $(ps -ef | grep -v grep | grep -i apollo | wc -l) > 0 ))
then
echo "Apollo MQTT is Running."
exit 0
else
echo "Apollo MQTT is Stopped."
exit 2
fi

关于linux - CentOS 7 pidof -x 不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38989804/

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