【发布时间】:2022-01-20 22:56:32
【问题描述】:
我正在尝试设置一个 Discord Webhook,用于在我的服务器上发布有关我的备份进程的信息。特别是作为嵌入 webhook 的 rsync 操作(大约 15 行摘要)的输出。
我决定使用 Discord.sh https://chaoticweg.cc/discord.sh/
这需要“line one\nnew line two\nthird line”的嵌入描述的字符串格式
由于 rsynclog 的输出跨越多行,我使用带有 jq 的脚本将其转换为这种格式。输入是:
Number of files: 101 (reg: 100, dir: 1)
Number of created files: 0
Number of deleted files: 0
Number of regular files transferred: 100
Total file size: 0 bytes
Total transferred file size: 0 bytes
Literal data: 0 bytes
Matched data: 0 bytes
File list size: 0
File list generation time: 0.001 seconds
File list transfer time: 0.000 seconds
Total bytes sent: 5,247
Total bytes received: 1,916
sent 5,247 bytes received 1,916 bytes 2,865.20 bytes/sec
total size is 0 speedup is 0.00
输出
"\nNumber of files: 101 (reg: 100, dir: 1)\nNumber of created files: 0\nNumber of deleted files: 0\nNumber of regular files transferred: 100\nTotal file size: 0 bytes\nTotal transferred file size: 0 bytes\nLiteral data: 0 bytes\nMatched data: 0 bytes\nFile list size: 0\nFile list generation time: 0.001 seconds\nFile list transfer time: 0.000 seconds\nTotal bytes sent: 5,247\nTotal bytes received: 1,916\n\nsent 5,247 bytes received 1,916 bytes 2,865.20 bytes/sec\ntotal size is 0 speedup is 0.00\n"
我通过复制粘贴新文件的全部内容作为 discord.sh 嵌入描述的参数来验证这是否有效,如下所示:
discord.sh --webhook-url=URL --description="THE CONTENT OF THE TEMP.JSON FILE PASTED IN HERE"
这产生了预期的结果:
问题
我不知道如何将转换后的日志文件的内容作为参数传递给 discord.sh。我用直接复制粘贴验证了文件的格式是正确的,但我无法让它在 bash 中读取文件的内容。
我尝试了什么:
$(< /path/to/file)$(cat /path/to/file)´/path/to/file´
我已经用尽了所有可以在网上找到的建议。它要么为包含无效 JSON 的消息返回错误,要么将文件内容的每个新单词视为新参数,并给我一个关于单词是无效参数的错误。即使文件清楚地包含引号,也应该将其视为一个字符串。
任何帮助将不胜感激
【问题讨论】:
标签: json linux bash discord webhooks