[Sderby] shell script for retrieving an image file from a remote
http server
Paul Grosse
paul-grosse at ntlworld.com
Sat Jul 3 00:19:41 BST 2004
Folks,
Does anybody know of a way (using commands that are likely to be found on
most people's machines) of retrieving an image file from a remote http host?
The commands would have to be representable in the form of a bash script
(suitable for running as a cron tab) and I would prefer not to have to have
people loading programs onto their machines in order to achieve this.
One thing that sprung to mind was the use of telnet (having the telnet
command in the shell script) with commands sent to it from its .telnetrc
file, redirecting the output to a file which could then have the first bits
of code removed as they are not part of the image.
Doing this manually, it is something along the lines of...
+++++++++++++++++++++++++++
==In BASH...
telnet www.xxx.yyy.zzz 80 >[some_directory]/image.png
==In Telnet...
GET /image.png HTTP/1.0[return]
Host:www.domain.com[return]
[return]
==In [some_directory], have a program that...
opens the file, finds the content-length data in the header returned by the
server.
Then, (possibly another program or line(s) of script) starts from the end
and counts that number of bytes towards the beginning then trunkates the
file, leaving just the image in the file (ie, chops the first bit off,
leaving the rest).
==Then, in [some directory] rename the file with the date and time (say, in
the form of 20040703000335.jpg)
+++++++++++++++++++++++++++
and that is all.
Is there a bit of perl that is something along the lines of lwp-retrieve ...
that will do the first part of this?
I think that using telnet is a bit long winded although I don't want to have
people loading libraries if they have a nice tight system and don't want
loads of other stuff there that might just compromise their security.
The idea is that people with web counters can retrieve the image for a
certain time of the week, every week without having to do it manually - the
only manual part is inspecting the images to collect the counter values.
Any ideas anyone???
Paul Grosse
More information about the Sderby
mailing list