linux - CentOS 7 pidof -x 不工作

标签 linux bash shell centos apollo

我有一个 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/

相关文章:

linux - awk 在算法中结合 for 和 while 循环

linux - 使用 xgettext 递归扫描文件

linux - 当应用程序在 Linux 中通过 crontab 运行时,Log4j2 日志记录不起作用

linux - 有没有一种方法可以在我的终端屏幕上显示标准输出并重定向到一个文件?

linux - 在bash中如何循环遍历以 "abc"开头的目录和目录 "special-dir"

linux - bash 脚本中的多线程

c++ - 为什么在这里使用进程替换会导致挂起?

shell - 在后台运行的 ssh 进程被暂停

linux - 使用 Bash shell 中内置的 'command'

json - 将文件作为字符串传递给 Github Gist REST API