Saturday, October 06, 2007

Perl script to automatically dowload files from a web site.

I've been reading Learning Perl book from Randal L. Schwartz and just the introduction gave me the tip to automate a task that otherwise would have taken more time.

Again I am installing Asterisk and a Debian box, I have a list of all the necessary files but now Asterisk put all the sounds files on separate files and not in one package as before.

Instead of downloading 31 pages manually I got a the link to all of them, put them on a file (named filesd) one o each line and run the following Perl script:

#!/usr/bin/perl
open (FILESD, filesd);
while ($pathf = ){
open (WGET, "wget $pathf");
close (WGET);
}


The filesd file is just a plain file like the one shown below:

ricardo@lmntel01:~/test$ more filesd
http://downloads.digium.com/pub/asterisk/releases/asterisk-1.4.12.1.tar.gz
http://downloads.digium.com/pub/zaptel/releases/zaptel-1.4.5.1.tar.gz
http://downloads.digium.com/pub/libpri/releases/libpri-1.4.1.tar.gz
http://downloads.digium.com/pub/asterisk/releases/asterisk-addons-1.4.3.tar.gz


I know this could have been done with WGET but I got tired of trying to find the correct flag to download them, and I also know there is no error check, report, fancy things and whistles but hey I just finish the introduction.

No comments: