How to use pastebin from shell script? How to use pastebin from shell script? bash bash

How to use pastebin from shell script?


As pastebin.com closed their public api, I was looking for alternatives.

Sprunge is great. Usage:

<command> | curl -F 'sprunge=<-' http://sprunge.us

or, as I use it:

alias paste="curl -F 'sprunge=<-' http://sprunge.us"<command> | paste


The documentation says that you need to submit a POST request to

http://pastebin.com/api_public.php

and the only mandatory parameter is paste_code, of type string is the paste that you want to make.

On success a new pastebin URL will be returned.

You can easily do this from your bash shell using the command curl.

curl uses the -d option to send the POST data to the specified URL.

Demo:

This demo will create a new paste with the code:

printf("Hello..I am Codaddict");

From your shell:

$ curl -d 'paste_code=printf("Hello..I am Codaddict");' 'http://pastebin.com/api_public.php'http://pastebin.com/598VLDZp$

Now if you see the URL http://pastebin.com/598VLDZp, you'll see my paste :)

Alternatively you can do it using the wget command which uses the option --post-data to sent POST values.

I've tried this command it works fine:

wget --post-data 'paste_code=printf("Hello..I am Codaddict");' 'http://pastebin.com/api_public.php'


Put the following in your .bashrc:

sprunge() {  if [[ $1 ]]; then    curl -F 'sprunge=<-' "http://sprunge.us" <"$1"  else    curl -F 'sprunge=<-' "http://sprunge.us"  fi}

...and then you can run:

sprunge filename # post file to sprunge

...or...

some_command | sprunge # pipe output to sprunge