2017-02-13 38 views
0

我想将通知发送到使用以下传入网络挂接松弛的通道是我对于如何使用在Linux 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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 

bash脚本运行此脚本我面对后这个错误,有人可以帮助我在我写作脚本做错了什么

sh new.sh 
curl: no URL specified! 
curl: try 'curl --help' or 'curl --manual' for more information 
+0

您需要在您的有效负荷的末端反斜杠,之前'https'。此外,删除第一行'#'后的空格(尽管这不是你问题的原因)。 – codeforester

+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 

它可能会提供一些线索,以你的问题。

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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