Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I want to make a shell script where I type an url and it returns me the status code.So far I've tested wget is there any other cause it has the tendency to save whatever you run. Then I tried to some kind awk the output but it doesn't do you have any advices.


Edit for Zelda: I tried the first one

enter image description here

but I always receive : enter image description here

P.S. Also I tried HTTP without '',now I putted for curiosity

share|improve this question
    
You left out 2>&1 from the wget ... line, that makes the output to stderr go to the pipe and grep. Quotes around HTTP not needed. –  Zelda Dec 14 '13 at 11:26
    
Oops, thx very much now it works –  Phil_Charly Dec 14 '13 at 11:36
add comment

2 Answers 2

up vote 5 down vote accepted

you can simply use curl for it.i have written a simple script for it.

url=$1

curl -sL $url -w "%{http_code} %{url_effective}\n" "URL" -o /dev/null

where URL is your URL which you have to test output will gives you status.

Example

image showing status for URL

share|improve this answer
add comment

You can just stick with wget:

wget -O /dev/null http://unix.stackexchange.com 2>&1 | grep -F HTTP

that gives you:

HTTP request sent, awaiting response... 200 OK

which you can further trim with cut:

wget -O /dev/null http://unix.stackexchange.com 2>&1 | grep -F HTTP | cut -d ' ' -f 6

If the url does not exist, then there is no output.

With query for url:

echo "give your url"
read url
wget -O /dev/null $url 2>&1 | grep -F HTTP
echo "ok?"
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.