4

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

2 Answers 2

6

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.
Sign up to request clarification or add additional context in comments.

Comments

1

add -S (upper) so you can still see errors:

from man: -S/--show-error Show error. With -s, make curl show errors when they occur

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.