我有一系列网址.我想打开它们,如果它们正在打开而没有任何错误,请将状态显示为正在运行,否则不运行.如何通过从当前输出中删除所有其他消息来实现下面提到的所需输出.
#!/bin/ksh
urlArray=('http://url1:port1' 'http://url2:port2' 'http://url3:port3')
for url in "${urlArray[@]}"
do
result=`curl $url | head -1`
if (echo $result | grep '<?xml' >/dev/null 2>&1); then
echo Running
else
echo Not Running
fi
done
Run Code Online (Sandbox Code Playgroud)
脚本的当前输出是
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 12980 0 12980 0 0 711k 0 --:--:-- --:--:-- --:--:-- 0
Running
curl: (6) Couldn't resolve host 'url2:port2'
Not Running
curl: (6) Couldn't resolve host 'url3:port3'
Not Running
Run Code Online (Sandbox Code Playgroud)
期望的输出:
Running
Not Running
Not Running
Run Code Online (Sandbox Code Playgroud)
该-s标志抑制输出:
$ curl foo
curl: (6) Couldn't resolve host 'foo'
$ curl -s foo
$
Run Code Online (Sandbox Code Playgroud)
从curl手册页:
-s/--silent
Silent or quiet mode. Don't show progress meter or error messages. Makes Curl mute.
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
7149 次 |
| 最近记录: |