通过WGET作为DATA发送多行命令输出

发布于 2025-02-01 17:29:07 字数 380 浏览 2 评论 0原文

我正在尝试运行一个命令,该命令将发送带有另一个命令结果的数据的发布请求。一个示例会说明这一点:

wget -O- --post-data=$(ls -lah) http://192.168.30.53/api/v2/network/clients

这显然是错误的,但是我不知道如何“逃脱” ls -lah命令的值,然后再将其作为参数传递。

如果需要,当前输出:

wget: invalid option -- '>'
wget: --wait: Invalid time period '-r--r--'

I'm trying to run a command that will send a POST request with data that is a result of another command. An example will say it all:

wget -O- --post-data=$(ls -lah) http://192.168.30.53/api/v2/network/clients

This is obviously wrong, but I have no idea how to "escape" the value of ls -lah command before passing it as a parameter.

Current output if needed:

wget: invalid option -- '>'
wget: --wait: Invalid time period '-r--r--'

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

面犯桃花 2025-02-08 17:29:08

您不会逃脱 - 您引用了用法。使用ShellCheck检查您的脚本。

... --post-data="$(ls -lah)" ...

You do not escape - you quote the usage. Check your scripts with shellcheck.

... --post-data="$(ls -lah)" ...
你是我的挚爱i 2025-02-08 17:29:08

我不知道如何“逃脱” ls -lah命令的值
将其作为参数传递。

wget man page描述- post-data =字符串- post-file = file insison,与这种情况相关的是

- post-data将字符串发送为数据,而- post-file发送
文件的内容。除此之外,它们以完全相同的方式工作。

的论点 - 邮政文件”必须是常规文件

,因为上述限制管道STDIN将行不通,但这不是问题,除非您禁止您创建正常文件 - 只需为那就

ls -lah > lsdata
wget -O- --post-file=lsdata http://192.168.30.53/api/v2/network/clients
rm lsdata

应该起作用(我没有测试的能力)

I have no idea how to "escape" the value of ls -lah command before
passing it as a parameter.

wget man page describe --post-data=string and --post-file=file in unison, relevant for this case is that

--post-data sends string as data, whereas --post-file sends the
contents of file. Other than that, they work in exactly the same way.

and that

argument to "--post-file" must be a regular file

due to above limitation piping stdin would not work, but that is not problem unless you are banning from creating normal files - just create temporary file for that, something like that

ls -lah > lsdata
wget -O- --post-file=lsdata http://192.168.30.53/api/v2/network/clients
rm lsdata

should work (I do not have ability to test it)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文