curl-users
Re: Determining if curl downloaded a newer file
Date: Mon, 10 Dec 2007 10:12:56 +0100
Gerard wrote:
> My question is, is there any way to determine, other than doing an explicit
> comparison of the files involved, if curl downloaded a newer file? There does
> not appear to be an exit code that I could use to determine this.
Well, if you get an error, you can assume the file has not been updated.
> I thought
> that the "-w" option might be useful; however, I cannot figure out how to
> capture it and use it in a variable. I was thinking that the "size_download"
> would be useful; however, I cannot figure out how to capture the value into a
> useful variable.
What's wrong with backticks?
http_code=`curl -s -w '%{http_code}' -O -z index.html http://www.example.com/index.html`
> I would welcome any suggestions.
http_code is more handy than size_download, as it includes any not found or server
error conditions that deliver a dummy html page, besides 304 "Not Modified". If you
want to capture more, you're probably better off using a temporary file, e.g.
curl -s -w 'http_code=%{http_code};size_download=%{size_download}' \
-O -z index.html http://www.example.com/index.html > curl_codes
if [ $? = 0 ]; then . ./curl_codes; fi
If you run curl under windows the exit code, a.k.a. error level, can be 0 in some
pathological circumstance where curl has not been run at all, thus some defensive
step is appropriate, e.g. (line broken for readability)
echo set http_code=0 > curl_codes.bat
curl -s -w "set http_code=%%{http_code}\nset size_download=%%{size_download}"
-O -z index.html http://www.example.com/index.html >> curl_codes.bat
call curl_codes.bat
Received on 2007-12-10