Welcome toVigges Developer Community-Open, Learning,Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
2.2k views
in Technique[技术] by (71.8m points)

shell重定向到/dev/null后grep获取不到值

写了个判断 spring cloud 项目是否启动的脚本,主要方法是:

curl http://ip:port/actuator/health | grep status

如果 echo $? 返回是 0,那应用就启动了,现在问题是 curl 会有一大串命令输出到屏幕上,我不想看到这些命令,于是:

curl http://ip:port/actuator/health >/dev/null 2>&1 | grep status

但是放到黑洞文件后,grep 就获取不到值了。。

我现在是把管道分割成单独命令,curl 输出到文件去:

curl http://ip:port/actuator/health >./curl.log 2>&1
grep status ./curl.log >/dev/null 2>&1

有其他办法嘛?


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

或许你需要的是安静模式?

curl -s http://ip:port/actuator/health | grep status 

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to Vigges Developer Community for programmer and developer-Open, Learning and Share
...