Posted By

zxeem on 05/15/09


Tagged

Bash download load hash wget rfc


Versions (?)

RFC Downloader Enhanced


 / Published in: Bash
 

URL: http://zxeem.wordpress.com

THERE IS A BUG AFTER COUNTING 100

  1. #!/bin/bash
  2. ####################################################
  3. # Created By Dino
  4. # An RFC [ Request for comment ] Files doewnloader.
  5. # to run ..
  6. # chmod +x rfcDownloader.sh
  7. # ./rfcDownloader.sh
  8. ####################################################
  9. # If you got slow connection .. increase this value.. not to burn your processor loading lots of wget instances
  10. SLEEP_TIME=0;
  11. RFC_MAX=6000;
  12.  
  13. # A repeater function .. repeats a character .. number of times
  14. # $1 the count times
  15. # $2 the character to repeat
  16. function repeater(){
  17. local counter=0;
  18. while [ $counter -le $1 ];do
  19. echo -e -n "$2";
  20. counter=`expr $counter + 1`;
  21. done
  22. }
  23.  
  24. # A function to clear line
  25. # $1 The width of the line ( characters count )
  26. function clearLine(){
  27. repeater 130 "\b"
  28. }
  29.  
  30. # A function to produce the --------- bar .. that is not yet filled with #######
  31. # $1 .. How many -- should appear ( not yet completed )
  32. function originalBar(){
  33. repeater $1 "-"
  34. }
  35.  
  36. # A function to produce the ######### bar .. that is already filled
  37. # $1 How many hashs should appear ( Completed )
  38. function loadBar(){
  39. repeater $hashs "#"
  40. }
  41.  
  42. # The Main hashloader ..
  43. function hashLoader(){
  44. # Number of hashs .. percentage $1 .. related to the total number .. $2
  45. local hashs=`expr $1 \* 100 / $2 `
  46. # Calculating how many percentage is still remaining
  47. local remaining=`expr 100 - $hashs`
  48. # Write the hashs to screen
  49. local hashChars=`loadBar $hashs`
  50. # Write the remainder -- to screen
  51. local originalChars=`originalBar $remaining`
  52. # The load note string
  53. local notes=" [ $hashChars$originalChars ] [ $hashs % | Done : $1 RFCs ]";
  54. # Calculating the notes characters length
  55. local notesSize=`echo $notes | wc -c`
  56. # Clear line
  57. clearLine $notesSize
  58. # Write the load note
  59. echo -e -n $notes
  60. }
  61.  
  62. function downloadRFCs(){
  63. local i=0;
  64. while [ $i -le $RFC_MAX ]; do
  65. #((i+=1))
  66. i=`expr $i + 1` ;
  67. if [ $i -le 9 ]; then
  68. wget -c "http://www.ietf.org/rfc/rfc000$i.txt" -o /dev/null &
  69. elif [ $i -le 99 ]; then
  70. wget -c "http://www.ietf.org/rfc/rfc00$i.txt" -o /dev/null &
  71. elif [ $i -le 999 ]; then
  72. wget -c "http://www.ietf.org/rfc/rfc0$i.txt" -o /dev/null &
  73. elif [ $i -le 9999 ]; then
  74. wget -c "http://www.ietf.org/rfc/rfc$i.txt" -o /dev/null &
  75. fi
  76. sleep $SLEEP_TIME;
  77. hashLoader $i $RFC_MAX
  78. done
  79. }
  80.  
  81.  
  82. #Hide cursor
  83. tput civis
  84. # Start downloading
  85. downloadRFCs
  86. # Show Cursor again
  87. tput cnorm

Report this snippet  

You need to login to post a comment.