Search code examples
httpbashshellurlpastebin

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?


Solution

  • 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'