我想检查应用程序的状态,如果它正在运行或没有。为此,我写了一个下面的脚本,但是作为一个新手,我不确定我如何在这里使用条件,如果"进程(pid)正在运行,URL是可访问的,那么只有应用程序正在运行"
代码:
#!/bin/bash
#Check: for java connector service
echo "Checking health of java connectors"
PID=$(ps -ef | grep test-core | grep -v grep | awk '{print $2}')
if [ -n "$PID" ]; then
echo "INFO: Java connector service is running"
else
echo "WARNING: Java connector service is not running"
fi
#Check for UI status
status="$(curl -Is http://172.217.23.16/application/authenticate | head -1)"
validate=( $status )
if [ ${validate[-2]} == "200" ]; then
echo "INFO: Application URL is up and running"
else
echo "WARNING: Application URL is NOT RESPONDING"
fi
我正在寻找类似if condition &&条件2满足,则"应用程序运行正常"。
这里的指导将非常有帮助。谢谢!
由于您已经计算了PID
和validate
的值,您可以通过执行
if [[ -n $PID && ${validate[-2]} == 200 ]]
then
...
fi