Capture http response code from wget | Unix Linux Forums | Shell Programming and Scripting

  Go Back    


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

Capture http response code from wget

Shell Programming and Scripting


Closed Thread    
 
Thread Tools Search this Thread Display Modes
    #1  
Old 11-17-2010
jack3698 jack3698 is offline
Registered User
 
Join Date: Nov 2010
Last Activity: 5 December 2010, 12:12 PM EST
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Capture http response code from wget

Hi All,

I am using wget to call a url..i am getting 202 if it is successful. if not i am forcing the response code to 417.

how can i capture the response code and print 0 if it is 202 and 1 if it is not 202

any ideas, please share

Thanks,
Jack.
Sponsored Links
    #2  
Old 11-17-2010
frans's Avatar
frans frans is offline Forum Advisor  
Registered User
 
Join Date: Oct 2009
Last Activity: 4 December 2013, 9:39 AM EST
Location: France
Posts: 839
Thanks: 4
Thanked 54 Times in 53 Posts
(($?==202)) will return 0 if $? is 202
Sponsored Links
    #3  
Old 11-18-2010
pludi's Avatar
pludi pludi is offline Forum Advisor  
Cat herder
 
Join Date: Dec 2008
Last Activity: 28 March 2014, 8:35 AM EDT
Location: Vienna, Austria, Earth
Posts: 5,522
Thanks: 38
Thanked 335 Times in 308 Posts
You'll want the --server-response option, eg
Code:
wget --server-response http://localhost/nx.file 2>&1 | awk '/^  HTTP/{print $2}'

Sponsored Links
Closed Thread

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Using WGET or CURL to HTTP Post with Authentication krypton Shell Programming and Scripting 2 02-26-2010 11:51 AM
Capture RSA fingerprint from ssh response chorlton Shell Programming and Scripting 0 04-10-2009 07:00 AM
cant make a http get request using wget elthox UNIX for Dummies Questions & Answers 1 02-20-2009 01:49 PM
Response Code using wget in shell rajbal Shell Programming and Scripting 2 09-28-2006 03:39 AM
wget using wildcards using http hcclnoodles Shell Programming and Scripting 2 04-13-2005 10:50 AM



All times are GMT -4. The time now is 07:35 PM.