Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- # this tool is handy to copy standard output from the command line to pastebin
- # it wil return your output with an URL.
- # refurbished by flip hess 2011
- # originator: http://www.anildewani.com
- # coder : Anil Dewani
- # date : Novemeber 7, 2010
- # Paste at Pastebin.com using command line (browsers are slow, right?)
- # Global variables:
- PATH='/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin'
- SCRIPT_PATH="${0}"
- # set empty var:
- NAME=
- EMAIL=
- TYPE=
- API="http://pastebin.com/api_public.php"
- # Functions:
- # exit function
- function die()
- {
- echo "${1}"
- exit 1
- }
- # The main function.
- function fMain()
- {
- #get options and set vars
- while getopts "n:e:t:h" OPTION
- do
- case ${OPTION} in
- n)
- NAME=${OPTARG}
- ;;
- e)
- EMAIL=${OPTARG}
- ;;
- t)
- TYPE=${OPTARG}
- ;;
- h)
- fShowUsage
- ;;
- ?)
- fShowUsage
- ;;
- esac
- done
- # check for stdin, if so, get it :)
- if [ "$( tty )" == 'not a tty' ]
- then
- INPUT="$(</dev/stdin)"
- else
- fShowUsage
- fi
- # check for empty input
- [ -z ${INPUT} ] && fShowUsage
- QUERYSTRING="paste_private=0&paste_code=${INPUT}&paste_name=${NAME}&paste_email=${EMAIL}&paste_format=${TYPE}"
- #post data to pastebin.com API
- curl -d "${QUERYSTRING}" "${API}"
- echo ""
- return 0
- }
- # Shows usage.
- function fShowUsage()
- {
- echo "Pastebin.com Bash Script"
- echo ""
- echo "Usage : ${SCRIPT_PATH} [ -n <paste name> ] [ -e <paste email> ] [ -t <type of code> ] [ -h ]"
- echo ""
- echo " <paste name> Specify the name of paste to be used (optional)"
- echo " <paste email> Specify email to be used while pasting (optional)"
- echo " <type of code> Specify code language used, use any of the following values (optional and default value is plain text)"
- echo ""
- echo "Example: \"echo \"Testing\" | ./${SCRIPT_PATH}\""
- echo ""
- echo "=> Some famous [ -t <type of code> ] Values:"
- echo ""
- echo " - php - PHP"
- echo " - actionscript3 - Action Script 3"
- echo " - asp - ASP"
- echo " - bash - BASH script"
- echo " - c - C language"
- echo " - csharp - C#"
- echo " - cpp - C++"
- echo " - java - JAVA"
- echo " - sql - SQL"
- echo ""
- exit 1
- }
- # do the magic:
- # first things first: check for curl
- [ -x "$(which curl)" ] || die "this script depends on curl"
- # Start the program:
- fMain "${@}"
- # Exit with previous return code:
- exit "${?}"
Advertisement
Add Comment
Please, Sign In to add comment