Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/bash/18.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Http 如何从shell脚本使用pastebin?_Http_Bash_Shell_Url_Pastebin - Fatal编程技术网

Http 如何从shell脚本使用pastebin?

Http 如何从shell脚本使用pastebin?,http,bash,shell,url,pastebin,Http,Bash,Shell,Url,Pastebin,是否可以在bashshell脚本中使用pastebin(可能是通过它们的脚本)?如何发送http post?如何取回URL?说明您需要向提交POST请求 http://pastebin.com/api_public.php 唯一的强制参数是paste\u code,类型为string的参数是要进行的粘贴 成功后,将返回一个新的pastebinURL 您可以使用命令curl从bashshell轻松地完成这项工作 curl使用-d选项将POST数据发送到指定的URL 演示: 此演示将使用以下代码创

是否可以在bashshell脚本中使用pastebin(可能是通过它们的脚本)?如何发送http post?如何取回URL?

说明您需要向提交
POST
请求

http://pastebin.com/api_public.php
唯一的强制参数是
paste\u code
,类型为string的参数是要进行的粘贴

成功后,将返回一个新的
pastebin
URL

您可以使用命令
curl
从bashshell轻松地完成这项工作

curl
使用
-d
选项将
POST
数据发送到指定的URL

演示:

此演示将使用以下代码创建新的粘贴:

printf("Hello..I am Codaddict");
从您的shell:

$ curl -d 'paste_code=printf("Hello..I am Codaddict");' 'http://pastebin.com/api_public.php'
http://pastebin.com/598VLDZp
$
现在,如果您看到URL,您将看到我的粘贴:)

或者您可以使用
wget
命令执行此操作,该命令使用选项
--post data
发送
post

我已经尝试过这个命令它工作正常:

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

当pastebin.com关闭其公共api时,我正在寻找替代方案

太好了。用法:

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

| curl-F'sprunge=将以下内容放入您的
.bashrc

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

some_command | sprunge # pipe output to sprunge

自codaddict发布以来,用于发布到pastebin的API已更改。
有关详细信息,请访问以下链接:

例如:

curl-d'api_paste_code=printf(“你好..\n我是Codaddict”);'\
-d'api_dev_key='1〕\
-d'api_选项=粘贴“”http://pastebin.com/api/api_post.php'

目前有三个基本字段:
api_dev_key
->您需要在pastebin.com上创建一个登录名才能获得该登录名
api\u选项
->发布格式
api\u-paste\u-code
->您想发布的文本

另外两个答案(大约2014年)指向,设计用于如下用途

curl --form 'sprunge=@yourfile.txt' sprunge.us
然而,截至2018年,sprunge.us有过载的趋势,每个请求返回500个内部服务器错误。对于至少300 KB但不高达2.8 MB的文件,我很幸运地在以下位置使用了非常类似的服务:

对于至少2.8MB(我不知道可能更高)的文件,我发现它们更精致。它建议使用稍有不同且更简单的命令行,并且需要
https
(没有它就无法工作):


我发现斯普林奇现在不在,但是

发帖

curl -s -F "content=<-" http://dpaste.com/api/v2/
发帖

curl -s -F "content=string" http://dpaste.com/api/v2/
响应将是指向粘贴的纯文本URL


Nb:URL
http://dpaste.com/api/v2/
似乎很有必要

的API比它们都简单。简单地“张贴”到它

网址:

Upload text using curl:
$ curl -s --data 'Hello World!' 'https://paste.c-net.org/'

Upload text using wget:
$ wget --quiet -O- --post-data='Hello World!' 'https://paste.c-net.org/'

Upload a file using curl:
$ curl --upload-file @'/tmp/file' 'https://paste.c-net.org/'

Upload a file using wget:
$ wget --quiet -O- --post-file='/tmp/file' 'https://paste.c-net.org/'

Upload the output of a command or script using curl:
$ ls / | curl --upload-file - 'https://paste.c-net.org/'
$ ./bin/hello_world | curl -s --data-binary @- 'https://paste.c-net.org/'
您也可以简单地使用netcat。与termbin不同,如果脚本生成输出所需时间超过5秒,则paste.c-net.org不会超时

$ { sleep 10; ls /; } | nc termbin.com 9999
$ { sleep 10; ls /; } | nc paste.c-net.org 9999
https://paste.c-net.org/ExampleOne
发布到pastebin的最简单方法
echo'your message'| sed'1s/^/api_paste_code=/g'| sed's/$/\%0A/g'| curl-d@--d'api_dev_key='-d'api_option=paste'http://pastebin.com/api/api_post.php'
只需更改
零件并将任何您想要的管道插入即可

sed
调用将
api\u paste\u code
参数添加到消息的开头,并在每行末尾添加一个换行符,以便它可以处理多行输入。
@-
告诉curl从stdin读取

可以粘贴的Bash函数 为便于重用,将其设置为bash函数(将其复制并粘贴到终端中,并适当设置
API\u键
字段:

pastebin(){
API_键=“”
如果[-z$1]
然后
cat-| sed'1s/^/api_-paste_-code=/g'| sed's/$/\%0A/g'| curl-d@--d'api_-dev_-key='“$api_-key”'-d'api_-option=paste”http://pastebin.com/api/api_post.php'
其他的
echo“$1”| sed'1s/^/api_-paste_-code=/g'| sed's/$/\%0A/g'| curl-d@--d'api_-dev_-key='“$api_-key”'-d'api_-option=paste'http://pastebin.com/api/api_post.php'
fi
printf'\n'
}
您可以使用以下任一选项运行它:

pastebin“您的邮件”

或者,如果需要通过管道将文件导入其中:


cat your_file.txt | pastebin

根据Vishal的回答,pastebin现在已升级为仅使用HTTPS:

curl -d 'api_paste_code=printf("Hello World");' \
     -d 'api_dev_key=<your_key>' \
     -d 'api_option=paste' 'https://pastebin.com/api/api_post.php'
curl-d'api\u paste\u code=printf(“你好世界”);'\
-d'api_dev_key='1〕\
-d'api_选项=粘贴“”https://pastebin.com/api/api_post.php'
您不必指定
-X POST
参数

更多详细信息可在此处找到:

基于,我编写了以下脚本,该脚本从STDIN读取(或假设输出通过管道传输到STDIN中)

此版本允许URI转义的任意数据(通过
jq


我写这篇文章有点晚了,但是我创建了一个小工具来帮助我

请随意查看,并让我知道您的想法


谢谢,

这已经被禁用了,新的API上有一个新的巴斯丁AppDIAL,这里可以找到:你需要一个<代码>开发者API键至少可以发布。已经发布了更新的细节。FYI,PaSTBIN网站上没有任何合适的浏览器插件的广告。请考虑使用不同的巴斯丁。,f'rinstance,两者(1)均不显示广告,且(2)包括从主页上的主要Shell发布到它的说明。@CharlesDuffy唯一的问题是长寿。Pastebin是迄今为止唯一一个经受住时间考验的Pastebin,从2002年就开始了。谁知道这些其他工具在各自的网站从DNS到期前会持续多久,无法向主机付款(放弃),主机破产。+1,警告说提供函数比提供别名更好——函数可以重新排序参数、执行逻辑、用于非交互shell等。获取“500内部服务器错误”另外,上次github提交是在2014年。如果您想使用pastebin而不是sprunge,请参阅我的答案C
cat foo.txt | curl -s -F "content=<-" http://dpaste.com/api/v2/
curl -s -F "content=string" http://dpaste.com/api/v2/
Upload text using curl:
$ curl -s --data 'Hello World!' 'https://paste.c-net.org/'

Upload text using wget:
$ wget --quiet -O- --post-data='Hello World!' 'https://paste.c-net.org/'

Upload a file using curl:
$ curl --upload-file @'/tmp/file' 'https://paste.c-net.org/'

Upload a file using wget:
$ wget --quiet -O- --post-file='/tmp/file' 'https://paste.c-net.org/'

Upload the output of a command or script using curl:
$ ls / | curl --upload-file - 'https://paste.c-net.org/'
$ ./bin/hello_world | curl -s --data-binary @- 'https://paste.c-net.org/'
$ { sleep 10; ls /; } | nc termbin.com 9999
$ { sleep 10; ls /; } | nc paste.c-net.org 9999
https://paste.c-net.org/ExampleOne
curl -d 'api_paste_code=printf("Hello World");' \
     -d 'api_dev_key=<your_key>' \
     -d 'api_option=paste' 'https://pastebin.com/api/api_post.php'
#!/bin/bash

api_key=XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

curl -d "api_paste_code=$(jq -sRr @uri)" \
     -d "api_dev_key=$api_key" \
     -d 'api_option=paste' 'https://pastebin.com/api/api_post.php'

echo  # By default, there's no newline