The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Advanced & Expert Users
.
google unix.com




View Single Post in the UNIX and Linux Forums - Click on the Thread or Permalink to View Entire Thread -->
  #2 (permalink)  
Old 10-07-2008
otheus's Avatar
otheus otheus is offline Forum Staff  
Moderator ala Mode
  
 

Join Date: Feb 2007
Location: Innsbruck, Austria
Posts: 1,864
The utility "wget" already does what you want to do. Check it out using the -N option. If the copy you have is older than the timestamp the webserver gives for the specified URL, a new copy is downloaded. If the file sizes do not match, a new copy is downloaded.

If you don't want it to actually download, but see what it would, do, you can use --spider. Then it reports what it would have done:
Code:
$ wget -N -v http://www.keepalived.org/documentation.html
--16:35:14--  http://www.keepalived.org/documentation.html
Resolving www.keepalived.org... 213.228.1.83
Connecting to www.keepalived.org|213.228.1.83|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 5035 (4.9K) [text/html]
The sizes do not match (local 0) -- retrieving.

--16:35:15--  http://www.keepalived.org/documentation.html
Reusing existing connection to www.keepalived.org:80.
HTTP request sent, awaiting response... 200 OK
Length: 5035 (4.9K) [text/html]
Saving to: `documentation.html'

100%[=======================================>] 5,035       --.-K/s   in 0.07s

16:35:15 (68.6 KB/s) - `documentation.html' saved [5035/5035]

[otheus] ~$ touch documentation.html
[otheus] ~$ wget -N -v http://www.keepalived.org/documentation.html
--16:36:08--  http://www.keepalived.org/documentation.html
Resolving www.keepalived.org... 213.228.1.83
Connecting to www.keepalived.org|213.228.1.83|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 5035 (4.9K) [text/html]
Server file no newer than local file `documentation.html' -- not retrieving.

[otheus] ~$ echo test >> documentation.html
Change the file size of documentation.html
[otheus] ~$ wget --spider -N -v http://www.keepalived.org/documentation.html
--16:36:27--  http://www.keepalived.org/documentation.html
Resolving www.keepalived.org... 213.228.1.83
Connecting to www.keepalived.org|213.228.1.83|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 5035 (4.9K) [text/html]
The sizes do not match (local 0) -- retrieving.

--16:36:27--  http://www.keepalived.org/documentation.html
Reusing existing connection to www.keepalived.org:80.
HTTP request sent, awaiting response... 200 OK
Length: 5035 (4.9K) [text/html]
200 OK