curl using https

I use the following command to get a result code from the web server. If 200, then all is good, if anything else, jump to something else in the script.

function primary_check()
        RES="$(curl -m 5 -o /dev/null --silent --head --write-out '%{http_code}\n' $IP1 -o /dev/null)"
        if [ ! $RES -eq 000 ];then
    # return a non empty value if all is good
                echo "GOOD"
    # don't return if there was an error

Open in new window

In the above,
curl -m 5 -o /dev/null --silent --head --write-out '%{http_code}\n' $IP1 -o /dev/null
returns simply 200 which is what I want.

Problem is... I need to start using https instead because I need to set up htpasswd on the server.

I am not having any luck returning only the result code so my question is looking for a solution.

curl -m 5 -k --key server.key --cert server.crt -o /dev/null --silent --head --write-out -u xxxx|xxxxxxx" '%{http_code}\n' -o /dev/null

-u-uHTTP/1.1 200 OK
Date: Mon, 20 Oct 2014 23:21:08 GMT
Server: Apache
Last-Modified: Sat, 02 Aug 2014 01:12:25 GMT
ETag: "2dc00fb-f-4ff9b32d9f040"
Accept-Ranges: bytes
Content-Length: 15
Connection: close
Content-Type: text/html; charset=UTF-8
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Double period

projectsAuthor Commented:
Just a typo. I've updated the question. Thanks.
This should just echo the response code

curl -m 5 -k --key server.key --cert server.crt -s -o /dev/null -u "xxxx|xxxxxxx"  -w '%{http_code}\n'

Open in new window

Introduction to R

R is considered the predominant language for data scientist and statisticians. Learn how to use R for your own data science projects.

projectsAuthor Commented:
Using the following;

curl -m 5 -k --key server.key --cert server.crt -s -o /dev/null -w -u "xxxx|xxxxxx" '%{http_code}\n'

The response is the single line in the index.html plus what you see in front.

-u-uNothing here!
projectsAuthor Commented:
Removing to -s to see what's going on... looks like an order of things?

# curl -m 5 -k --key server.key --cert server.crt -o /dev/null -w -u "xxxx|xxxxxx" '%{http_code}\n'
curl: (6) Couldn't resolve host 'xxxx|xxxxxx'
curl: (6) Couldn't resolve host '%http_code\n'
-u-uNothing here!
That's not the same as I posted (I may have edited it while you were copying it)
projectsAuthor Commented:
Your does the same thing but remember, I also don't have any name/passwd to google so it'll fail anyhow.

Yours does return the code however but it's a 000
That's just an example, if you press enter on the challenge you'll get the response code (000 - connection cancelled) , but you should be entering your URL and user/pass

In cygwin you will get 000 in Linux you will get 302
projectsAuthor Commented:
Yes, I have substituted my own info of course.
That's what I posted above.

Let me check, I bet I've got a typo.
projectsAuthor Commented:
# curl -m 5 -k --key server.key --cert server.crt -s -o /dev/null -u "xxxx|xxxxxx"  -w '%{http_code}\n'
Enter host password for user 'xxxx|xxxxxx':

So, the above is what I'm using, with my own certs, name/pass and server of course.
It keeps prompting me for the name/password but does give me a 200 after I hit return.
projectsAuthor Commented:
This is on Linux.
I shouldn't have relied on your code being right

curl -m 5 -k --key server.key --cert server.crt -u xxxx:xxxxxxx -s -o /dev/null  -w '%{http_code}\n'

Open in new window

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
projectsAuthor Commented:
What does that mean??
This bit
-u xxxx:xxxxxxx

You had
-u xxxx|xxxxxxx
projectsAuthor Commented:
Yes, I see that too now. I have no idea how that got in there because my code actually uses the semi colon.
Maybe another typo when I was editing the question, sorry.

Works as it should, thanks very much. I'll test it and award shortly.
projectsAuthor Commented:
curl -m 5 -k --key server.key --cert server.crt -u xxxx:xxxxxxx -s -o /dev/null  -w '%{http_code}\n'

So same thing, without the authentication
curl -m 5 -s -o /dev/null  -w '%{http_code}\n'

Cool, that's what I was struggling with. Thanks very much.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Shell Scripting

From novice to tech pro — start learning today.