Return to Snippet

Revision: 14028
at May 15, 2009 20:33 by zxeem


Initial Code
#!/bin/bash
####################################################
# Created By Dino
# An RFC [ Request for comment ] Files doewnloader.
# to run ..
# chmod +x rfcDownloader.sh
# ./rfcDownloader.sh
####################################################
# If you got slow connection .. increase this value.. not to burn your processor loading lots of wget instances 
SLEEP_TIME=0;
RFC_MAX=6000;

# A repeater function .. repeats a character .. number of times
# $1 the count times
# $2 the character to repeat
function repeater(){
	local counter=0;
	while [ $counter -le $1 ];do
		echo -e -n "$2";
		counter=`expr $counter + 1`;
	done
}

# A function to clear line
# $1 The width of the line ( characters count )
function clearLine(){
	repeater 130 "\b"
}

# A function to produce the --------- bar .. that is not yet filled with #######
# $1 .. How many -- should appear ( not yet completed )
function originalBar(){
	repeater $1 "-"
}

# A function to produce the ######### bar .. that is already filled
# $1 How many hashs should appear ( Completed )
function loadBar(){
	repeater $hashs "#"
}

# The Main hashloader .. 
function hashLoader(){
	# Number of hashs .. percentage $1 .. related to the total number .. $2 
	local hashs=`expr $1 \* 100 / $2 `
	# Calculating how many percentage is still remaining 
	local remaining=`expr 100 - $hashs`
	# Write the hashs to screen
	local hashChars=`loadBar $hashs`
	# Write the remainder -- to screen
	local originalChars=`originalBar $remaining`
	# The load note string
	local notes=" [ $hashChars$originalChars ] [ $hashs % | Done : $1 RFCs ]";
	# Calculating the notes characters length
	local notesSize=`echo $notes | wc -c`
	# Clear line
	clearLine $notesSize
	# Write the load note
	echo -e -n $notes
}

function downloadRFCs(){
	local i=0;
	while [ $i -le $RFC_MAX ]; do
		#((i+=1))
		i=`expr $i + 1` ;
		if [ $i -le 9 ]; then
		wget -c "http://www.ietf.org/rfc/rfc000$i.txt" -o /dev/null &
		elif [ $i -le 99 ]; then
		wget -c "http://www.ietf.org/rfc/rfc00$i.txt" -o /dev/null &
		elif [ $i -le 999 ]; then
		wget -c "http://www.ietf.org/rfc/rfc0$i.txt" -o /dev/null &
		elif [ $i -le 9999 ]; then
		wget -c "http://www.ietf.org/rfc/rfc$i.txt" -o /dev/null &
		fi
		sleep $SLEEP_TIME;
		hashLoader $i $RFC_MAX
	done
}


#Hide cursor
tput civis
# Start downloading
downloadRFCs
# Show Cursor again
tput cnorm

Initial URL
http://zxeem.wordpress.com

Initial Description
THERE IS A BUG AFTER COUNTING 100

Initial Title
RFC Downloader Enhanced

Initial Tags
Bash, download, load

Initial Language
Bash