写个简单脚本使用if 语句 根据curl --connect-timeout 3 http17216100489042healthInfo结果来判断2种结果 并echo 不同内容
#!/bin/bash
执行 curl 命令,设置连接超时时间为 3 秒
result=$(curl --connect-timeout 3 'http://172.16.100.48:9042/healthInfo')
判断结果
if [ "$result" == "OK" ]; then echo "服务正常" else echo "服务异常" fi
或者使用 if-else if-else 结构
if [ "$result" == "OK" ]; then echo "服务正常" elif [ "$result" == "ERROR" ]; then echo "服务出错" else echo "未知状态" fi
原文地址: http://www.cveoy.top/t/topic/bixC 著作权归作者所有。请勿转载和采集!