dkanavis

AutoFetcher

Jun 10th, 2015
310
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 1.35 KB | None | 0 0
  1. ### Script Fetches url for n times
  2.  
  3. URL="http://www.maaaaaaaaaak.ru"
  4. PRBLEN=10
  5.  
  6. if [ "$#" -lt 1 ]; then
  7.     echo "Usage: $0 <times> [url]"
  8.     echo  "   times - how much requests should the script do"
  9.     echo  "   url - URL to examine (default is $URL)"
  10.     exit 255
  11. fi
  12.  
  13. if [ "$2" != "" ]; then URL=$2; fi
  14.  
  15.  
  16. check_bin() {
  17.     if [ `which $1` == "" ]; then
  18.          echo "$1 command not found. Please install $1"
  19.          exit 255
  20.     fi
  21. }
  22.  
  23. if [ `uname -s` == "FreeBSD" ]; then
  24.     FREE_BSD=1
  25.     check_bin "fetch"
  26. else
  27.     if [ `uname -s` == "Linux" ]; then
  28.         FREE_BSD=0
  29.         check_bin "wget"
  30.     else
  31.         echo Unsupported OS `uname -s`
  32.         exit 255
  33.     fi
  34. fi
  35.  
  36. total=0
  37. err=0
  38. while [ "$total" != "$1" ]; do
  39.     if [ $FREE_BSD == "1" ]; then
  40.         fetch -o /dev/null $URL > /dev/null 2>&1
  41.     else
  42.         wget -O /dev/null $URL > /dev/null 2>&1
  43.     fi
  44.     if [ "$?" != "0" ]; then
  45.         ((err=err+1))
  46.     fi
  47.     ((total=total+1))
  48.     ((percent=total*100/$1))
  49.     ((prg=total*PRBLEN/$1))
  50.     printf "\r["
  51.     counter=0
  52.     while [ $counter -lt $PRBLEN ]; do
  53.         if [ $counter -lt $prg ]; then
  54.             echo -n "*"
  55.         else
  56.             echo -n " "
  57.         fi
  58.         ((counter=counter+1))
  59.     done
  60.     echo -n "]" $total/$1 \($percent\%\)
  61. done
  62.  
  63. echo ""
  64.  
  65. echo Total: $total
  66. echo Err: $err
Advertisement
Add Comment
Please, Sign In to add comment