Advertisement
HashWorks

Pastebin BASH Script

Feb 10th, 2015
2,738
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 1.39 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. API_DEV_KEY='';  # Required, see http://pastebin.com/api#1
  4. API_USER_KEY=''; # Optional, empty = guest, see http://pastebin.com/api#8
  5.  
  6. #########################################################################################
  7.  
  8. # default values
  9. NAME=
  10. FORMAT=
  11. PRIVATE=0
  12. EXPIRE_DATE=N
  13.  
  14. while getopts "n:f:e:hpu" OPTION
  15. do
  16.     case $OPTION in
  17.     n)
  18.         NAME=$OPTARG
  19.         ;;
  20.     f)
  21.         FORMAT="&api_paste_format=${OPTARG}"
  22.         ;;
  23.     e)
  24.         EXPIRE_DATE=$OPTARG
  25.         ;;
  26.     p)
  27.         PRIVATE=2
  28.         ;;
  29.     u)
  30.         PRIVATE=1
  31.         ;;
  32.     ?)
  33.         echo "\
  34. Pastebin.com Bash Script \
  35. Usage : $0 [ -n <name> ] [ -f <format> ] [ -e <expiration> ] [ -p | -u ] [ -h ]
  36.  
  37. Input data using STDIN.
  38.  
  39. -n Specify the name of paste to be used
  40. -f Specify code format used, use any of the values here http://pastebin.com/api#5
  41. -e Specify expiration time, default never, examples here http://pastebin.com/api#6
  42. -p Set paste private, requires a userkey, default public
  43. -u Set paste unlisted, default public
  44. "
  45.         exit
  46.         ;;
  47.     esac
  48. done
  49.  
  50. INPUT="$(</dev/stdin)"
  51.  
  52. querystring="api_option=paste&api_dev_key=${API_DEV_KEY}&api_user_key=${API_USER_KEY}&api_paste_expire_date=${EXPIRE_DATE}&api_paste_private=${PRIVATE}&api_paste_code=${INPUT}&api_paste_name=${NAME}${FORMAT}"
  53.  
  54. curl -d "${querystring}" http://pastebin.com/api/api_post.php
  55.  
  56. echo ""
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement