我正在编写一个简单的 Linux shell 脚本来检查正在运行的服务的状态,如果有任何进程未运行,它将显示未运行的进程的名称。
我已经在下面尝试过,现在卡在了 else 语句中。 我想要输出的 else 语句是显示的 4 个变量中具有非零值的变量的名称。
如果 RUNWRAPPERSTATUS 和 EKYCSTATUS 不为零,输出应该如下所示。
There is some while starting RUNWRAPPER AND EKYC . Kindly verify
实际代码从这里开始:
ps -aef | grep -i NGEjbClient
RUNWRAPPERSTATUS=$(echo $?)
ps -aef | grep -i startSMS
RUNSTATUS=(echo $?)
ps -aef | grep -i DirectoryService
DISSTATUS=(echo $?)
ps -aef | grep -i EKYCUploadWorkitem
EKYCSTATUS=(echo $?)
if [ $RUNWRAPPERSTATUS -eq 0 ] && [ $RUNSTATUS -eq 0 ] && [ $DISSTATUS -eq 0 ] && [ $EKYCSTATUS -eq 0 ]
then
echo "Jboss Services and App Services started"
最佳答案
展示您可以做什么的简单脚本:
SERVICES="NGEjbClient startSMS DirectoryService EKYCUploadWorkitem"
for service in $SERVICES
do
if ! pgrep $service
then
echo "$service is not running. Please verify"
fi
done
注意事项:
- 使用
pgrep
搜索进程名 - 尽可能使用循环来避免重复代码。
关于linux - Linux shell 脚本中的条件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57884025/