#!/bin/bash
#
# get_it.sh							Nov 2005
#
# (GPL) Marno van der Molen - marno.vandermolen@gmail.com
#
# Filegetter with resume function
# 
# This script starts at the number given at COUNTER, and increments
# until the number given at MAX. It will get the file at the given URL
# with the given EXT (extension, without dot). This is handy for example
# when there are a lot of files in a database which you want to download.
# This would be a lot of work to do manually, so that's why I made this
# little script. It saves the last file it started with in a file in the
# current directory. This file is called 'state'. If you remove this it
# starts over from the file given at COUNTER.
#
# The state file takes care of the resume-feature, so don't remove it unless
# you don't want to resume!
#
COUNTER=3180
MAX=5600
URL='https://82.94.0.174/Files/server/fotos/'
#URL='http://marno.homelinux.com/mysql/images/'
EXT='jpg'
STATEFILE='.state'
if [ -r $STATEFILE ]
then
COUNTER=`cat state`
#let COUNTER-=1
fi
ALLREADY=0
NEW=0
FAILED=0

while [ $COUNTER -ne $MAX ]
do
	echo $COUNTER > state
	let COUNTER+=1

	echo -n "Now getting ${COUNTER}.jpg "
	wget ${URL}${COUNTER}.${EXT} --no-check-certificate > /dev/null 2>&1
	
	if [ $? = 0 ]
	then
		echo "[SUCCES]"
		let NEW+=1
	else
		echo "[FAILED]"
		let FAILED+=1
	fi
done
echo "Failed: $FAILED, New: $NEW. Done!"

