2017-02-13 77 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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