写一个shell脚本判断curl -o /dev/null -s -w %{http_code} http://192.168.0.173/riskWeb/secureBaseApp/tenant/tenantByUser的返回值是否等于200,等于的话,输出$(date "+%Y-%m-%d_%H:%M:%S"), cyb-secureBase" is running",如果不等于去判断pid=`ps -ef | grep /app/service/cyb-secureBase/app.jar | grep -v grep | awk '{print $2}'是否有值输出,有的话echo $(date "+%Y-%m-%d_%H:%M:%S"), cyb-secureBase" is running",没有执行nohup java -Xms256m -Xmx1024m -Xmn256m -Dfile.encoding=utf-8 -jar /app/service/cyb-secureBase/app.jar > app.log 2>&1 &
时间: 2024-04-20 22:25:01 浏览: 135
可以参考下面的Shell脚本来实现你的需求:
```shell
#!/bin/bash
# 发送GET请求,并获取返回状态码
response_code=$(curl -o /dev/null -s -w "%{http_code}" http://192.168.0.173/riskWeb/secureBaseApp/tenant/tenantByUser)
# 判断返回状态码是否等于200
if [ $response_code -eq 200 ]; then
echo "$(date "+%Y-%m-%d_%H:%M:%S"), cyb-secureBase is running"
else
# 判断进程是否存在
pid=$(ps -ef | grep /app/service/cyb-secureBase/app.jar | grep -v grep | awk '{print $2}')
if [ -n "$pid" ]; then
echo "$(date "+%Y-%m-%d_%H:%M:%S"), cyb-secureBase is running"
else
nohup java -Xms256m -Xmx1024m -Xmn256m -Dfile.encoding=utf-8 -jar /app/service/cyb-secureBase/app.jar > app.log 2>&1 &
fi
fi
```
将以上代码保存为脚本文件(比如`check_service.sh`),然后通过`chmod +x check_service.sh`添加执行权限。运行脚本`./check_service.sh`即可完成判断和执行操作。
阅读全文