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!
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 ^^'
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.
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?
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"
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:
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
[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