How to test for file update


 
Thread Tools Search this Thread
Top Forums UNIX for Advanced & Expert Users How to test for file update
# 1  
Old 10-07-2008
How to test for file update

I would like to test if a file has been updated from a website located here:

I-BlockList

Is there anyway to do this from the command line (I'd like to add it to a script). I'd just like to either:

(a) See if the file has been updated by looking at the file's 'Date Modified' or

(b) Compare the file size with one I have downloaded earlier.

Of course the file is located on a remote server so you can't use the usual 'ls' commands, and if you use wget, then you'll download it, which may not be necessary if the file hasn't be updated...

Thanks in advance for your help.

Craig

Last edited by DukeNuke2; 10-07-2008 at 05:25 AM.. Reason: removed link...
# 2  
Old 10-07-2008
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

Login or Register to Ask a Question

Previous Thread | Next Thread

6 More Discussions You Might Find Interesting

1. 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

2. Shell Programming and Scripting

Prefixing test case methods with letter 'test'

Hi, I have a Python unit test cases source code file which contains more than a hundred test case methods. In that, some of the test case methods already have prefix 'test' where as some of them do not have. Now, I need to add the string 'test' (case-sensitive) as a prefix to those of the... (5 Replies)
Discussion started by: royalibrahim
5 Replies

3. Shell Programming and Scripting

Problem in test file operator on a ufsdump archive file mount nfs

Hi, I would like to ask if someone know how to test a files if exist the file is a nfs mount ufsdump archive file.. i used the test operator -f -a h almost all test operator but i failed file1=ufs_root_image.dump || echo "files doesn't exist && exit 1 the false file1 is working but... (0 Replies)
Discussion started by: jao_madn
0 Replies

4. Shell Programming and Scripting

Update LDIF User info based on Test User Certs ID's

Hi I need help.......... I have an Sun One Directory server LDIF file with 5000 user entries, I need to change the data to match Test ID's, so I can run a perf test. I'm way out of my league as I have not done any scripting for 10 years. There are four entries for each user in the file... (3 Replies)
Discussion started by: Macdaddy99
3 Replies

5. Shell Programming and Scripting

How to check weather a string is like test* or test* ot *test* in if condition

How to check weather a string is like test* or test* ot *test* in if condition (5 Replies)
Discussion started by: johnjerome
5 Replies

6. Shell Programming and Scripting

Test on string containing spacewhile test 1 -eq 1 do read a $a if test $a = quitC then break fi d

This is the code: while test 1 -eq 1 do read a $a if test $a = stop then break fi done I read a command on every loop an execute it. I check if the string equals the word stop to end the loop,but it say that I gave too many arguments to test. For example echo hello. Now the... (1 Reply)
Discussion started by: Max89
1 Replies
Login or Register to Ask a Question