LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 05-16-2012, 07:41 PM   #1
masavini
Member
 
Registered: Jun 2008
Posts: 285

Rep: Reputation: 6
wget --spider $webdir


hi,
is it possibile to use wget --spider to check for web directory existance?

plain command doesn't seem to work:
Code:
$ wget -q --spider "www.li-tech-shop.it/tmp/"
$ echo $?
8
it seems to give $? == 0? only if some sort of index file exists.
how to get $? == 0? if no index file is present but directory actually exists?

thanks...
 
Old 05-17-2012, 01:33 AM   #2
cliffordw
Member
 
Registered: Jan 2012
Location: South Africa
Posts: 509

Rep: Reputation: 203Reputation: 203Reputation: 203
Hi there,

wget returns 8 (Server issued an error response) for both a non-existent directory and a directory which exists but you don't have access to (like your example where there is no index and directory listings are not allowed). They return different HTTP response codes, though.

I'd suggest you don't use the "-q" option. Without it wget returns the HTTP response, which you can interpret. For the URL in your example, the return code is 403 (Forbidden), while for a non-existent directory it would be 404 (Not Found).

Using curl with the --head option instead of wget might be easier to use for this particular purpose.

I hope this helps.
 
1 members found this post helpful.
Old 05-17-2012, 03:25 AM   #3
masavini
Member
 
Registered: Jun 2008
Posts: 285

Original Poster
Rep: Reputation: 6
thank you!

Code:
			_dirCheck=$(curl -s --head "$_remoteDir")
			if [[ $_dirCheck =~ "404 Not Found" ]]; then
				echo "open -u $global__ftpUsr,$global__ftpPwd $global__ftpHost" > $_script
				echo "mkdir -p $_remoteDir" >> $_script
				echo "exit" >> $_script
				lftp -q -f $_script &> /dev/null
			fi
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
wget, web crawler, web spider and web archiving beckettisdogg Linux - Newbie 1 08-16-2009 07:27 AM
Spider software or similar? bruno buys Linux - Software 2 10-26-2005 09:20 PM
wget as web spider/crawler kpachopoulos Linux - Software 2 08-27-2005 12:58 PM
LAN Spider? sir_September Linux - Networking 2 03-19-2004 05:38 PM
Spider Clone for linux Maranza Linux - Software 3 02-01-2004 07:52 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 03:45 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration