Download archives script

Lets say you have a directory full of files that are named foobar01.tar.gz, foobar02.tar.gz … foobar50.tar.gz and you wont to download dem all. Here are a sample script that will do this.

You need to adapt it to handle the numbers of files, the URI and filename for your needs.

#!/bin/sh

#Loop through all the files
i=1
while [ "$i" -le 50 ]
do
if [ "$i" -lt 10 ] 
then
i=0$i
fi

# Build the URI to download
FILE1="http://www.example.com/archives/foobar"
FILE2=".tar.gz"
FILE="$FILE1$i$FILE2"

# Local filename
FILELOCAL=phrack$i$FILE2

# Get the file with wget
wget $FILE

#Unpack the file
tar -xzf $FILELOCAL

# Delete the *.tar.gz file
rm -f $FILELOCAL

i=`expr $i + 1`
done