Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use pastebin from shell script?

Is it possible to use pastebin (may be via their "API" functionality) inside bash shell scripts? How do I send http-post? How do I get back the URL?

like image 416
litro Avatar asked Oct 25 '10 11:10

litro


2 Answers

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 
like image 124
user2291758 Avatar answered Sep 23 '22 19:09

user2291758


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' 
like image 31
codaddict Avatar answered Sep 22 '22 19:09

codaddict