Skip to content

Instantly share code, notes, and snippets.

@janbaer
Forked from cyrus-and/pastebin.sh
Created January 29, 2021 17:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save janbaer/00f951b759740e013eff9b4a8c6bf804 to your computer and use it in GitHub Desktop.
Save janbaer/00f951b759740e013eff9b4a8c6bf804 to your computer and use it in GitHub Desktop.
Quick way to pipe data to pastebin.com directly from shell
#!/usr/bin/env bash
# usage: <command> | pastebin [+|++|+++]
#
# (none): paste expires in 10 minutes
# +: paste expires in 1 hour
# ++: paste expires in 1 day
# +++: paste expires in 1 months
HOST='pastebin.com'
# cleanup
trap 'rm -f $TEMPFILE' EXIT
# get expiration from command line
declare -A EXPIRE_DATES=([0]=10M [+]=1H [++]=1D [+++]=1M)
EXPIRATION=${EXPIRE_DATES[${1:-0}]:-${EXPIRE_DATES[0]}}
# show prompt message in interactive mode only
if [ -t 0 ] ; then
echo '# Write your paste (Ctrl-C to abort and Ctrl-D to submit):'
fi
# fill the paste
TEMPFILE=$(tempfile)
cat > $TEMPFILE
# retrieve the token
echo '# Loading...'
TOKEN=$(curl -s $HOST | \
sed -n 's/^.*input name="post_key" value="\(.*\)" type="hidden".*$/\1/p')
# submit the paste
echo "# http://$HOST"\
$(curl -s "$HOST/post.php" \
-D - \
-F 'submit_hidden=submit_hidden' \
-F "post_key=$TOKEN" \
-F 'paste_format=1' \
-F "paste_expire_date=$EXPIRATION" \
-F 'paste_private=1' \
-F "paste_code=<$TEMPFILE;type=text/plain" \
| awk '/^location: / { print $2 }')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment