I have an array of url's. I want to open them and if they are opening up without any error , show the status as running else not running. How can I achieve the desired output mentioned below, by removing all other messages from current output.
#!/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
Current output of script is
% 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
Desired output:
Running
Not Running
Not Running
The -s
flag suppresses output:
$ curl foo
curl: (6) Couldn't resolve host 'foo'
$ curl -s foo
$
From the curl man page:
-s/--silent
Silent or quiet mode. Don't show progress meter or error messages. Makes Curl mute.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With