如果有可用的文件比一天新,我正在尝试发送一条松弛消息。
完整命令
find . -mtime -1 -exec curl -X POST -H 'Content-type: application/json' --data '{"text":"Hello, World!"}' https://hooks.slack.com/services/FooBar {} \;
该命令不起作用,但会引发错误。
输出:
okcurl: (6) Could not resolve host:
okcurl: (6) Could not resolve host:
okcurl: (6) Could not resolve host:
答案 0 :(得分:0)
@larsks已经提到,通过{}
插入curl
的文件名显然被解释为主机名,因此会产生该错误。
如果将{}
放入消息的text属性中,它将起作用,然后将找到的文件名包含在发送到Slack Webhook的消息中。我想不仅发送一条消息,而且在该消息中包含该文件的名称也很有意义。
find . -mtime -1 -exec curl -X POST -H 'Content-type: application/json' --data '{"text":"Hello, World! {}"}' https://hooks.slack.com/services/FooBar \;
或者,如果您不想在Slack上显示找到的文件名,则可以完全省略{}
:
find . -mtime -1 -exec curl -X POST -H 'Content-type: application/json' --data '{"text":"Hello, World!"}' https://hooks.slack.com/services/FooBar \;
最后,我假设您不想发送有关“”的消息。目录,因此您需要将其排除:(从here)
find . -mtime -1 -not -path "." -exec curl -X POST -H 'Content-type: application/json' --data '{"text":"Hello, World!"}' https://hooks.slack.com/services/Foobar \;