LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
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 12-16-2011, 10:11 AM   #1
sopier
Member
 
Registered: Dec 2011
Location: Jogja, Indonesia
Distribution: Ubuntu
Posts: 33

Rep: Reputation: Disabled
Dead link checker in bash


Hi, I have a code like this:

Code:
#!/bin/bash

function isLive {
    wget -q --spider $1
}

isLive "http://supremecourtofindia.nic.in/ecommittee/25%20Salient%20Features%20of%20Ubuntu%20Linux%20OS%20DVD.pdf"

if [ $? -eq 0 ]; then
    echo "Good link"
else
    echo "Broken link"
fi
The link is live, I can download the pdf using browser, but the script can't process the url, and hang...

Any solution on this?
 
Old 12-16-2011, 10:16 AM   #2
H_TeXMeX_H
LQ Guru
 
Registered: Oct 2005
Location: $RANDOM
Distribution: slackware64
Posts: 12,928
Blog Entries: 2

Rep: Reputation: 1301Reputation: 1301Reputation: 1301Reputation: 1301Reputation: 1301Reputation: 1301Reputation: 1301Reputation: 1301Reputation: 1301Reputation: 1301
Try:

Code:
wget -q --spider --user-agent="Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.0.1) Gecko/20060111 Firefox/1.5.0.1" http://supremecourtofindia.nic.in/ecommittee/25%20Salient%20Features%20of%20Ubuntu%20Linux%20OS%20DVD.pdf
 
Old 12-16-2011, 10:36 AM   #3
sopier
Member
 
Registered: Dec 2011
Location: Jogja, Indonesia
Distribution: Ubuntu
Posts: 33

Original Poster
Rep: Reputation: Disabled
Thank you... it works like charm....
 
Old 12-16-2011, 07:38 PM   #4
sopier
Member
 
Registered: Dec 2011
Location: Jogja, Indonesia
Distribution: Ubuntu
Posts: 33

Original Poster
Rep: Reputation: Disabled
Hey, I'm improving the script like below:

Code:
#!/bin/bash

function isLive {
    wget -q --spider --spider --connect-timeout=5 --user-agent="Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.0.1) Gecko/20060111 Firefox/1.5.0.1" $1
}

isLive "http://reksio.ftj.agh.edu.pl/~azrael/ubuntu/marketing/po_polsku/wersje%20robocze/Ubuntu_wallet.pdf"

if [ $? -eq 0 ]; then
    echo "Good link"
else
    echo "Broken link"
fi
and when I run the script, it freeze out... How to set timeout properly? So, if after xx seconds frozen, it can be categorized as broken links...
 
Old 12-16-2011, 07:44 PM   #5
sopier
Member
 
Registered: Dec 2011
Location: Jogja, Indonesia
Distribution: Ubuntu
Posts: 33

Original Poster
Rep: Reputation: Disabled
Never mind, it's solved, I add the --tries=xx argument in the wget option, so the script will looks like this:

Code:
#!/bin/bash

function isLive {
    wget -q --spider --spider --connect-timeout=5 --tries=3 --user-agent="Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.0.1) Gecko/20060111 Firefox/1.5.0.1" $1
}

isLive "http://reksio.ftj.agh.edu.pl/~azrael/ubuntu/marketing/po_polsku/wersje%20robocze/Ubuntu_wallet.pdf"

if [ $? -eq 0 ]; then
    echo "Good link"
else
    echo "Broken link"
fi
 
Old 12-17-2011, 10:14 PM   #6
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 10,007

Rep: Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192
As you are using bash you can also use 'if' to do the test for you:
Code:
if command; then
    <if true>
else
    <if false>
fi
 
  


Reply



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
Is Petstore forum a dead link? darkcity Puppy 3 11-27-2011 06:29 AM
Bash - Spell Checker ericvolpone Programming 13 10-10-2011 03:15 PM
Dead kernel link B4lulu Linux - Newbie 4 08-28-2007 10:30 PM
SCIM dead link wangberg Linux - Desktop 0 06-28-2007 08:05 PM
IPv6 - link dead samjaynes Linux - Newbie 1 03-09-2007 12:28 PM

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

All times are GMT -5. The time now is 05:06 PM.

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