Posting data to Pastebin with cURL
by Jaku on Sep.20, 2009, under Code, Haxs
I needed to get a bunch of text up on pastebin and I’ve used my own cURL script to get it up there before. But then I started to think that others might want to be able to just post to pastebin directly from their bash shell. What started off as a simple one-liner then started to grow into a bit more.
With pastebin you are able to post to a sub-domain, as well as put a name along with the post and even set how long the data should stay up. So I’ve made it possible for you to edit those settings in the script so that if you want to post as “bob” and keep the data up there for a day you can do all of that.
The easiest way to install this would be the following 2 commands
sudo curl haxbyjaku.com/pastebin -o /usr/bin/pastebin
sudo chmod +x /usr/bin/pastebin
I know that you won’t run sudo on commands that download code from my server, but you can trust it since you get to see everything.
After it is installed I suggest editing the file as well so that you can set your own settings such as username or pastebin URL. Once that is all set simple run a command like "echo test | pastebin" in your terminal and you’ll get the URL that pastebin posted it to. You can even do something like "echo /etc/passwd | pastebin" and it will work exactly as you expect it to.
I’ve pasted the code after the break as well.
#!/bin/bash
#Pastebin poster, created by Jaku
#Username
USER="jaku_bin"
#Data retainment (d=1 day, m=1 month, f=forever)
RETAIN="d"
#Default Text type (too many to list)
TEXT="None"
#Default pastbin URL
URL="pastebin.com/pastebin.php"
while read input; do
CODE="$CODE
$input"
done
curl -i -d "code2=$CODE&paste=Send&expiry=$RETAIN&poster=$USER&format=$TEXT" $URL -s| grep -i Location:
So like I said, it’s not very complicated but it certainly does get the job done. Let me know if you have any comments or questions!

January 5th, 2010 on 3:01 pm
Thanks for posting this! A great start on something I’ve needed for a while.
I overhauled it for my own purposes and incorporated it into my ‘dotfiles’ collection as a utility script.
Mine will be available through github:
January 5th, 2010 on 3:01 pm
(My last post didn’t seem to include the url…)
http://github.com/samba/dotfiles/blob/master/bin/pastebin
January 8th, 2010 on 7:47 am
I did have some problems with this, since there’s not URI encoding. My code got cut off at > <
January 8th, 2010 on 8:10 am
I figured it out, and what you need to do is curl -i –data-urlencode “code2=$CODE” -d “paste=Send&expiry=$RETAIN&poster=$USER&format=$TEXT”
July 13th, 2010 on 6:57 am
hello, he doesn’t work for me, i have changed
URL=”pastebin.com/pastebin.php”
by
URL=”pastebin.com/post.php”
and nothing is done, if you can fix your post, thank you
December 28th, 2010 on 4:24 am
Wow, these comments all got blocked in SPAM and I just now got around to finding them. It’s great to see that some of you have found this useful.
Mooi, I suggest looking at the GitHub fork that Sam made over at http://github.com/samba/dotfiles/blob/master/bin/pastebin