我正在尝试使用下面的传入webhook向松弛频道发送通知是我的bash脚本
# !/bin/sh
curl -X POST --data-urlencode 'payload={"channel": "#aws_webhooks", "username": "webhookbot",
"attachments":[
{
"fallback":"blahb",
"pretext":"blahblahblahblahbla",
"color":"warning",
"fields":[
{
"title":"Alarms Updates",
"value":" blahblahblahblahblahblah",
"short":false
}
]
}
]
}'
https://hooks.slack.com/services/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
运行此脚本后,我遇到了这个错误,有人可以帮助我编写脚本中的错误
sh new.sh
curl: no URL specified!
curl: try 'curl --help' or 'curl --manual' for more information
答案 0 :(得分:0)
不确定您的代码会发生什么,但您可以查看我在此处写的bash客户端:https://github.com/openbridge/ob_hacky_slack
以下是为帖子创建的代码段:
# Send the payload to the Slack API
echo "OK: All tests passed, sending message to Slack API..."
POST=$(curl -s -S -X POST --data-urlencode "${PAYLOAD}" "${WEBHOOK}${TOKEN}");
# Check if the message posted to the Slack API. A successful POST should return "ok". Anything other than "ok" indicates an issue
if test "${POST}" != ok; then echo "ERROR: The POST to the Slack API failed (${POST})" && return 1; else echo "OK: Message successfully sent to the channel ${CHANNEL} via the Slack API"; fi
它可能会为您的问题提供一些线索。
答案 1 :(得分:0)
你应该添加一个' \'如果网址在一个单独的行上:
# !/bin/sh
curl -X POST --data-urlencode 'payload={"channel": "#aws_webhooks", "username": "webhookbot",
"attachments":[
{
"fallback":"blahb",
"pretext":"blahblahblahblahbla",
"color":"warning",
"fields":[
{
"title":"Alarms Updates",
"value":" blahblahblahblahblahblah",
"short":false
}
]
}
]
}' \ <-------backslash
https://hooks.slack.com/services/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