script to open the specified url in a browser from a text file


 
Thread Tools Search this Thread
Top Forums UNIX for Advanced & Expert Users script to open the specified url in a browser from a text file
# 1  
Old 08-22-2007
script to open the specified url in a browser from a text file

Hi All,

here i am struc
# 2  
Old 08-22-2007
Could you be more specific like what do you want to achieve by opening URL in the browser? and also which browser do you want to open this URL?

If you want to download something from URL, you could use wget without any browser onto your box.
# 3  
Old 08-22-2007
I am having a text file which has url's in it.

so i want to write a script where it gets the url from the text file and opens the url if it is correct and existing, if not it should comment the one which is not existing.

example:
now i saved a file by name slist, which contains data as

http://yahoomail.com/
http://yahoommail.com/
http://gmail.com/
http://gmmaaiill.com/ and so on.

from this slist file which has url's , it should open each of the url's and check whether they are valid and are opening, if not valid (may be some 404 page not found errors are any problem) then those url's should be commented out in the slist file as shown below.
#htp:/gmail.com/
http://yahoomail.com/
#http://yahoommail.com/
http://gmail.com/
#http://gmmaaiill.com/


i tried as

wget -i ./sitelist

and it displayed as,
$ wget -i ./sitelist
------------------------------------------------------------------------
./sitelist: Invalid URL htp:/gmail.com/: Unsupported scheme
--07:04:31-- http://yahoomail.com/
=> `index.html'
Resolving yahoomail.com... 216.109.112.135, 66.94.234.13
Connecting to yahoomail.com|216.109.112.135|:80... connected.
HTTP request sent, awaiting response... 301 Moved Permanently
Location: http://mail.yahoo.com/ [following]
--07:04:32-- http://mail.yahoo.com/
=> `index.html'
Resolving mail.yahoo.com... 209.73.168.74
Connecting to mail.yahoo.com|209.73.168.74|:80... connected.
HTTP request sent, awaiting response... 302 Found
Location: https://login.yahoo.com/config/login_verify2?&.src=ym [following]
--07:04:32-- https://login.yahoo.com/config/login_verify2?&.src=ym
=> `login_verify2?&.src=ym'
Resolving login.yahoo.com... 209.73.168.74
Connecting to login.yahoo.com|209.73.168.74|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: unspecified [text/html]

[ <=> ] 26,138 --.--K/s

07:04:32 (44.43 MB/s) - `login_verify2?&.src=ym' saved [26138]

--07:04:32-- http://gmail.com/
=> `index.html'
Resolving gmail.com... 72.14.253.83, 64.233.171.83, 64.233.161.83
Connecting to gmail.com|72.14.253.83|:80... connected.
HTTP request sent, awaiting response... 302 Found
Cookie coming from gmail.com attempted to set domain to google.com
Location: http://mail.google.com/mail/ [following]
--07:04:32-- http://mail.google.com/mail/
=> `index.html'
Resolving mail.google.com... 209.85.147.19, 209.85.147.18, 209.85.147.83
Connecting to mail.google.com|209.85.147.19|:80... connected.
HTTP request sent, awaiting response... 302 Moved Temporarily
Location: https://www.google.com/accounts/Serv...l&passive=true
&rm=false&continue=http%3A%2F%2Fmail.google.com%2Fmail%2F%3Fui%3Dhtml%26zy%3Dl&l
tmpl=default&ltmplcache=2 [following]
--07:04:33-- https://www.google.com/accounts/Serv...=mail&passive=
true&rm=false&continue=http%3A%2F%2Fmail.google.com%2Fmail%2F%3Fui%3Dhtml%26zy%3
Dl&ltmpl=default&ltmplcache=2
=> `ServiceLogin?service=mail&passive=true&rm=false&continue=http:%2F
%2Fmail.google.com%2Fmail%2F?ui=html&zy=l&ltmpl=default&ltmplcache=2'
Resolving Google... 72.14.253.103, 72.14.253.99, 72.14.253.147, ...
Connecting to www.google.com|72.14.253.103|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 16,131 (16K) [text/html]

100%[====================================>] 16,131 --.--K/s

07:04:33 (110.83 KB/s) - `ServiceLogin?service=mail&passive=true&rm=false&contin
ue=http:%2F%2Fmail.google.com%2Fmail%2F?ui=html&zy=l&ltmpl=default&ltmplcache=2'
saved [16131/16131]

--07:04:33-- Gmmail.com
=> `index.html'
Resolving gmmail.com... 206.207.87.4
Connecting to gmmail.com|206.207.87.4|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: unspecified [text/html]

[ <=> ] 32,276 172.51K/s

07:04:34 (172.20 KB/s) - `index.html' saved [32276]

--07:04:34-- http://yahoommail.com/
=> `index.html.1'
Resolving yahoommail.com... 216.109.112.135, 66.94.234.13
Connecting to yahoommail.com|216.109.112.135|:80... connected.
HTTP request sent, awaiting response... 404
07:04:34 ERROR 404: (no description).


FINISHED --07:04:34--
Downloaded: 74,545 bytes in 3 files

------------------------------------------------------------------------

So please suggest to get the following output
# 4  
Old 08-22-2007
Grep for "Invalid URL" and "Host not found" (better, take cases in consideration) and you get the results for all wrong sites.

Another issue you have here, is that sites like Gmmail.com and http://yahoommail.com/ DO EXIST, but in your case these have to be considered as wrong ones.. For such popular sites, maintain valid URLs in a file and check against to.
# 5  
Old 08-23-2007
If you use Perl to do it, it would require a simple while() loop and a call to LWP module to get the HTTP headers. It is likely more reliable as it does not need to parse the "messy" output of wget or any other similar command line tools.
# 6  
Old 08-23-2007
Hi cbkihong,

to say i am not good in perl script, i am just a beginner, but i can understand the script written in perl with little bit of difficulty.....

so will u let me know the script .........(may be in perl as u told), then if it is possible suggest me how can i get rid of it using shell script.


my intention is read urls from a file (what ever url's it may be) but the url's which are not opening i.e which displays 404 , page not found error and so on should be commented in the file with # symbol.


for the correct url's : nothing to be done(except script should validate whether the url is working or not)

for the wrong urls's : script should place a # symbol infront of the url in a file
example: # http://yahoommail.com/


Kindly help me out with a script...... pls
# 7  
Old 08-23-2007
I believe the practice of this forum is not to encourage excessive spoon feeding, instead, to give you pointers for you to explore on your own, to give you an opportunity to learn.

The HEAD HTTP method is frequently used instead of GET to get the headers without downloading the message body. That seems to fit what you want. But you can use GET if you like.

Look at this for example:
http://search.cpan.org/~gaas/libwww-...808/lib/LWP.pm

I think it should be enough to get you going about the HTTP part. For the file writing part, you should read some Perl documentation for file I/O for further information.

Please try to assemble something on your own first and post for advice before asking for more code given. Thanks.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Extracting the column containing URL from a text file

I have the file like this: Timestamp URL Text 1331635241000 http://example.com Peoples footage at www.test.com,http://example4.com 1331635231000 http://example1.net crack the nuts http://example6.com 1331635280000 http://example2.net ... (3 Replies)
Discussion started by: csim_mohan
3 Replies

2. Shell Programming and Scripting

Extracting the column containing URL from a text file

I have the file like this: Timestamp URL Text 1331635241000 http://example.com Peoples footage at www.test.com,http://example4.com 1331635231000 http://example1.net crack the nuts http://example6.com 1331635280000 http://example2.net ... (0 Replies)
Discussion started by: csim_mohan
0 Replies

3. Shell Programming and Scripting

Extracting the column containing URL from a text file

I have the file like this: Timestamp URL Text 1331635241000 http://example.com Peoples footage at www.test.com,http://example4.com 1331635231000 http://example1.net crack the nuts http://example6.com 1331635280000 http://example2.net ... (0 Replies)
Discussion started by: csim_mohan
0 Replies

4. HP-UX

Browser to check URL in hpux.

Hello Expert, I want to test the url in hp-ux, so it is possible via putty ?? Also have xmanager on the same system. (5 Replies)
Discussion started by: purushottamaher
5 Replies

5. Shell Programming and Scripting

Hit multiple URL from a text file and store result in other test file

Hi, I have a problem where i have to hit multiple URL that are stored in a text file (input.txt) and save their output in different text file (output.txt) somewhat like : cat input.txt http://192.168.21.20:8080/PPUPS/international?NUmber=917875446856... (3 Replies)
Discussion started by: mukulverma2408
3 Replies

6. Shell Programming and Scripting

How to find invalid URL in a text file using shell script?

How to find and remove invalid URLs in a text file using shell script? (1 Reply)
Discussion started by: vel4ever
1 Replies

7. Shell Programming and Scripting

Text substitution & getting file name from url

hi, sorry if this seems trivial. i have a file url.txt which consists of a list of urls (it was supposed to be my wget -i file). however, since the server from which i am trying to download uses redirect, wget dows not remeber the filename of ther original url will save to a file name which is... (3 Replies)
Discussion started by: texttoolong
3 Replies

8. UNIX for Dummies Questions & Answers

open windows's .url file in unix

In windows, I can create a shortcut for websites. It's a .url file. the content of the file is like: How can I open it, the .url file, in firefox or google chrome in Unix(or just ubuntu)? (2 Replies)
Discussion started by: hz_i3
2 Replies

9. Shell Programming and Scripting

Displaying text file in browser - perl

Don't know why this didn't get posted before but... I am having issues displaying a log file in the browser using perl and I can't get it to display at all, All i get is WHITE (blank page). I have proper permissions in my cgi-bin directory and everywhere else. So I know that's NOT the issue. ... (3 Replies)
Discussion started by: Dabheeruz
3 Replies

10. Shell Programming and Scripting

Displaying text file in browser - perl

I am having issue dispalying text file in browser using perl. Here is my code: #!/usr/bin/perl print "content-type: text/html \n\n"; open (FH , "access.log") || die "Blah $!"; while (<FH>) { print $_ ; } I have correct permissions and everything. The weired thing is when I... (1 Reply)
Discussion started by: Dabheeruz
1 Replies
Login or Register to Ask a Question