Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
Erstellungsdatum einer Datei auf einen Webserver abfragen?
View unanswered posts
View posts from last 24 hours
View posts from last 7 days

 
Reply to topic    Gentoo Forums Forum Index Deutsches Forum (German) Diskussionsforum
View previous topic :: View next topic  
Author Message
3PO
Veteran
Veteran


Joined: 26 Nov 2006
Posts: 1110
Location: Schwabenländle

PostPosted: Sat Oct 27, 2007 8:18 am    Post subject: Erstellungsdatum einer Datei auf einen Webserver abfragen? Reply with quote

Hallo Zusammen,

ich hänge mal wieder bei der Erstellung eines Scripts.

Gibt es einen Möglichkeit, das Erstellungsdatum einer Datei auf einen Webserver, mit einen Script abzufragen, ohne die Datei downzuloaden?

Beispiel:

Ich möchte wissen, ob die Datei: h++p://www.beispiel.url/upload/update.tar.gz neuer ist als die Datei : /var/update/update.tar.gz

Ist so etwas machbar, und falls ja, wie?

Bin über jeden Tipp dankbar. :D
Back to top
View user's profile Send private message
think4urs11
Bodhisattva
Bodhisattva


Joined: 25 Jun 2003
Posts: 6659
Location: above the cloud

PostPosted: Sat Oct 27, 2007 9:33 am    Post subject: Reply with quote

Code:
curl -sI http://www.erdbeerbaer.de/mein-backup-von-2006.tar | sed '/Last-Modified/!d'

_________________
Nothing is secure / Security is always a trade-off with usability / Do not assume anything / Trust no-one, nothing / Paranoia is your friend / Think for yourself
Back to top
View user's profile Send private message
3PO
Veteran
Veteran


Joined: 26 Nov 2006
Posts: 1110
Location: Schwabenländle

PostPosted: Sat Oct 27, 2007 9:44 am    Post subject: Reply with quote

Danke für die schnelle Antwort.

Der Befehl, den Du gepostet hast gibt in meinen Beispiel folgenden Wert zurück:
Code:
Last-Modified: Fri, 26 Oct 2007 20:20:44 GMT


Leider habe ich keinen Ahnung wie ich das in mei Script einbaunen muss.

seither hatte ich das so gelöst:
Code:
.....
if [[ /var/update/update.tar.gz -nt /var/update/tmp/update.tar.gz ]] ; then
   echo test1
else
   echo test2
fi
.....
Back to top
View user's profile Send private message
think4urs11
Bodhisattva
Bodhisattva


Joined: 25 Jun 2003
Posts: 6659
Location: above the cloud

PostPosted: Sat Oct 27, 2007 12:20 pm    Post subject: Reply with quote

möglich wäre es z.B. etwa so (und ja es geht sicher eleganter aber es geht ums Prinzip)

a) via curl wie oben das last-modified-date holen; curl -sI http://blubb.de/bla.tar | sed '/Last-Modified/!d'
b) dieses in epoch umwandlen (Sekunden seit 1.1.1970); damit läßt sich später einfacher vergleichen
dazu muß erst noch alles abgeschnitten werden was kein Datum ist damit es umgerechnet werden kann
wir modifizieren dazu das Kommando aus a) zu curl -sI http://blubb.de/bla.tar | sed '/Last-Modified/!d;s/.*: \(.*\)/\1/'
ergibt z.B. Fri, 26 Oct 2007 20:20:44 GMT
Umrechnung geht z.B. mittels des date Kommandos so: date -d"Fri, 26 Oct 2007 20:20:44 GMT" +%s; ergibt 1193430044
c) Wert in eine Variable 'remote' packen
d) mit dem Datum der lokalen Datei analog verfahren und das epoch-date in 'lokal' packen
e) und dann bleibt nur noch ein einfacher 'if $remote neuer als $lokal then wget datei'

Wenn nun z.B. deine lokale Datei ein Datum Fri, 26 Oct 2007 23:18:32 GMT aufweist (epoch 1193440712), ergibt der Vergleich das das Update nicht gezogen werden muß, da die lokale Datei neuer ist.
_________________
Nothing is secure / Security is always a trade-off with usability / Do not assume anything / Trust no-one, nothing / Paranoia is your friend / Think for yourself
Back to top
View user's profile Send private message
3PO
Veteran
Veteran


Joined: 26 Nov 2006
Posts: 1110
Location: Schwabenländle

PostPosted: Sun Oct 28, 2007 11:05 am    Post subject: Reply with quote

Habe es jetzt so gelöst:

Code:
#!/bin/bash

update_URL=http://www.blabla.com/upload/update.tar.gz
DATUM_NEU="$(curl -sI $update_URL| sed '/Last-Modified/!d;s/.*: \(.*\)/\1/')"

/var/update/

if [ "$DATUM_NEU" != "" -a "$(cat /var/update/Datum)" != "$DATUM_NEU" ] ; then
   wget $update_URL
   echo "$DATUM_NEU" >  /var/update/Datum
fi

exit


Danke nochmal, für den Stups in die richtige Richtung. :wink:
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Deutsches Forum (German) Diskussionsforum All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum