我有一个url数组。我想打开它们,如果它们在没有任何错误的情况下打开,则显示状态为正在运行,否则未运行。如何通过从当前输出中删除所有其他消息来实现下面提到的所需输出。
#!/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
脚本的当前输出是
% 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
期望的输出:
Running
Not Running
Not Running