Ask for Version of Script on Server w/o download

Hello!

I'm sorry if my question is kind of a noob question, but I'm searching for a way to "ask" a Server for the Version of a File. The problem is I have several clients asking every hour or so for the newest version of the file, so if I'm just downloading a md5sum or so I'm getting a lot of Traffic... Is there a possibility to get something (w/o downloading a file) from the server to determine the version? Like the Server passes a variable or a string to the client.

Thanks for replys and sorry for my bad english! :slight_smile:

ps: I'm sorry if the question is answered by googling, but I couldn't find anything, mostly because I don't really know what to search for ^^'

What kind of server.

A normal ftp server
The thing is, I don't really want to download something every hour, a string given upon a reqest would be much easier to handle.

Store an md5sum in a different file and have your clients check that, but it sounds like you already guessed that and are looking for something automatic. FTP doesn't have that, no. FTP is very simple and stupid.

1 Like

What about HTTP? It's possible to access the server via HTTP, I'm just downloading the files via FTP ^^
Oh and thanks for the quick replys! :):b:

HTTP doesn't have checksums, but it does have timestamps.

Do your clients have wget?

$ wget -N localhost/~tyler/hugefile
--2010-11-09 10:39:01--  http://localhost/~tyler/hugefile
Resolving localhost... 127.0.0.1
Connecting to localhost|127.0.0.1|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 16777216 (16M) [text/plain]
Saving to: `hugefile'

100%[======================================>] 16,777,216   106M/s   in 0.2s

2010-11-09 10:39:01 (106 MB/s) - `hugefile' saved [16777216/16777216]

$ wget -N localhost/~tyler/hugefile
--2010-11-09 10:39:03--  http://localhost/~tyler/hugefile
Resolving localhost... 127.0.0.1
Connecting to localhost|127.0.0.1|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 16777216 (16M) [text/plain]
Server file no newer than local file `hugefile' -- not retrieving.
1 Like

This looks just perfect :slight_smile:
Didn't knew wget can check for newer file, should have read the manpage better >_>
Anyways, thanks a lot :b:

Corona688s solution works flawless, th eonly problem I got now, is to check in my script where I use wget, what wgets check sayed.
Here's a part of my script:

wget -N -a $logfile -t 0 http://www.google.com/
if [ $? -eq 0 ]
then
     [what to do if new file was downloaded from server]
else
     [what to do if local file isn't updated]
fi

Anyone got an answer to my problem? :frowning:
Thanks in advance!

Hm, it returns success in either case. Have to check its error output instead.

TMP=`mktemp`
if wget -N http://server/file 2> "$TMP"
then
        if grep -q "Not retrieving" "$TMP"
        then
                echo "Already up to date"
        else
                echo "New file retrieved"
        fi
else
        echo "Couldn't download file"
fi
rm -f "$TMP"

[edit] A smarter way might be by what wget itself does, check timestamps.

TMP=`mktemp`
# Set temp file to the same timestamp as current file
touch --reference=outputfile "$TMP"

if wget -N http://path/to/file
then
        # Compare timestamps.  If outputfile is newer, it got updated
        if [ outputfile -nt "$TMP" ]
        then
                echo "New file downloaded"
        else
                echo "No new version"
        fi
else
        echo "Error retrieving file"
fi
# Don't clutter up /tmp
rm -f "$TMP"
1 Like

Thanks a LOT :slight_smile:
I got so much problems with wget, I hope that was the last thing >_>

I'm sorry t say this, but my code is still causing trouble T_T
The first solution doesn't work because I need to write every output in a logfile, if I'm trying to do it like this:

wget -N -t 0 http://somesite/somefile 2> "$TMP"
$TMP >> logfile

I'm getting an error "Permission denied"...
It works well and recognizes that there's no new update but I still need to write everything in a logfile >_>

[edit]: I forgot to mention: I got several update procedures in one logfile, so it's not possible to grep "Not retrieving" out of it :confused:

[edit2]; Silly me... solved it ^^

TMP=/some/where/tempfile.txt
wget -N -t 0 http://somesite/somefile 2> "$TMP"
$TMP >> logfile
if cat $TMP | grep -q "Not retrieving"
then
     echo "Theres no newer version..."
else
     echo "New File downloaded!"
fi

Works perfect :slight_smile: