Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
2.6k 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 Reply

0 votes
by (71.8m points)

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

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...