metalx1000

Bulk Download Pastebin Files

Nov 16th, 2014
462
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 1.02 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. if [ $# -lt 1 ]
  4. then
  5.     echo "Useage: $0 <user> <number of Pages>"
  6.     echo "Example: $0 metalx1000 2"
  7.     exit 0
  8. fi
  9.  
  10. user="$1"
  11. if [ $# -lt 2 ]
  12. then
  13.     let pages=1
  14.     echo "Downloading $pages of ${user}'s pastes."
  15. else
  16.     let pages=$2
  17.     echo "Downloading $pages of ${user}'s pastes."
  18. fi
  19.  
  20.  
  21. for x in $(seq 1 $pages)
  22. do
  23.     echo "Downloading Page $x"
  24.     wget -q "http://pastebin.com/u/$user/$x" -O-|grep "t.gif"|grep "Public paste"|while read line
  25.     do
  26.         id="$(echo $line|cut -d\" -f10|cut -d\/ -f2)"
  27.         title="$(echo $line|cut -d\" -f11|cut -d\> -f2|cut -d\< -f1|cut -d\. -f1)"
  28.         url="http://pastebin.com/raw.php?i=${id}"
  29.         echo "Downloading $title..."
  30.        
  31.         wget -q -c "$url" -O "$title"
  32.    
  33.         type="$(head -n1 "$title")"
  34.  
  35.         if [[ $type == *bash* ]]
  36.         then
  37.             mv "$title" "${title}.sh"
  38.         elif [[ $type == *python* ]]
  39.         then
  40.             mv "$title" "${title}.py"
  41.         fi
  42.        
  43.     done
  44. done
  45.  
  46. dos2unix *
Add Comment
Please, Sign In to add comment